[Leetcode] 77. Combinations
·
코딩테스트/Python
🔗 Problem Link Combinations - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com ❔Thinking 1부터 n까지의 숫자들 가운데 k개를 뽑아 조합한 결과를 반환한다. 💻Solution 1. 조합을 활용한 풀이 from itertools import combinations def combine(self, n: int, k: int): n_list = [i for i in range(1,n+1)] return list(combinations(n_..
[Leetcode] 46. Permutations
·
코딩테스트/Python
🔗 Problem Link Permutations - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com ❔Thinking 주어진 숫자들을 모두 활용해 만들 수 있는 수열을 리스트에 담아 반환한다. 💻Solution 1. 조합을 활용한 풀이 from itertools import permutations def permute(self, nums): return list(permutations(nums, len(nums))) 2. DFS를 활용한 풀이 - 반복문 def ..
[Leetcode] 17. Letter Combinations of a Phone Number
·
코딩테스트/Python
🔗 Problem Link Letter Combinations of a Phone Number - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com ❔Thinking 2에서 9까지 숫자가 주어질 때, 각 숫자에 적힌 알파벳으로 가능한 조합을 모두 담은 리스트를 반환한다. 💻Solution 1. 조합을 활용한 풀이 from itertools import product def letterCombinations(self, digits: str) -> List[str]: ..
[Leetcode] 200. Number of Islands
·
코딩테스트/Python
🔗 Problem Link Number of Islands - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com ❔Thinking 0은 물, 1은 땅을 나타내는 grid가 주어질 때, 섬의 개수를 반환한다. 💻Solution 1. while을 활용한 DFS 풀이 def numIslands(grid: List[List[str]]) -> int: island = 0 m, n = len(grid), len(grid[0]) for i in range(m): for j in..
[Programmers] Level 2. 행렬 테두리 회전하기
·
코딩테스트/Python
🔗 Problem Link 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr ❔Thinking 주어진 직사각형 범위의 테두리를 시계방향으로 회전하고, 이 테두리에서 가장 작은 값들을 출력한다. 💻Solution def solution(rows, columns, queries): answer = [] matrix = [] # 행렬 생성 for i in range(1, rows*columns, columns): tmp = [] for j in range(i, i+columns): tmp.append(j) matrix.append(tmp) # matrix = [[..
[Programmers] Level 3. 가장 먼 노드
·
코딩테스트/Python
🔗 Problem Link 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr ❔Thinking 1부터 시작하여 연결된 노드 중 가장 먼 거리의 노드의 개수를 반환한다. 💻Solution from collections import deque def solution(n, edge): graph = [[] for i in range(len(edge)+1)] distance = [-1] * (n+1) # 그래프 연결하기 for e in edge: start, end = e graph[start].append(end) graph[end].append(start) # ..