프로그래머스 43163. 단어 변환
·
프로그래머스
https://school.programmers.co.kr/learn/courses/30/lessons/43163 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.krvisited가 set인 경우def solution(begin, target, words): if target not in words: return 0 # target이 words에 없으면 변환 불가 # 단어 간 1글자 차이를 확인하는 함수 def is_one_char_diff(word1, word2): diff_count = 0 for a, b in zip(word1, word2): ..
프로그래머스 1844. 게임 맵 최단거리
·
프로그래머스
https://school.programmers.co.kr/learn/courses/30/lessons/1844 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.krfrom collections import dequedef solution(maps): n = len(maps[0]) # 열의 크기 m = len(maps) # 행의 크기 visited = [[0] * n for _ in range(m)] # n x m 크기의 방문 배열 def bfs(start): q = deque([start]) visited[start[0]][start[1]] = 1 ..
프로그래머스 43165. 타겟 넘버
·
프로그래머스
https://school.programmers.co.kr/learn/courses/30/lessons/43165 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr1. dfs 풀이def solution(numbers, target): ans = 0 # 타겟 넘버를 만드는 방법의 수 def dfs(depth, current_sum): nonlocal ans # 모든 숫자를 사용한 경우 if depth == len(numbers): if current_sum == target: ans += 1 ..
프로그래머스 84512. 모음사전
·
프로그래머스
https://school.programmers.co.kr/learn/courses/30/lessons/84512 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr1. dfs 완전탐색 index 풀이def solution(word): dict = [] words = 'AEIOU' def dfs(cnt, w): if cnt == 5: return for i in range(len(words)): dict.append(w + words[i]) dfs(cnt+1, w+words[i]) dfs(0, "..
프로그래머스 42839. 소수 찾기
·
프로그래머스
https://school.programmers.co.kr/learn/courses/30/lessons/42839?language=python3 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr[itertools 풀이]import mathfrom itertools import permutationsdef solution(numbers): # 소수 판별 함수 def isPrime(number): if number [재귀 풀이]primeSet = set()def isPrime(number): if number in (0, 1): return False for i ..
프로그래머스 42579. 베스트앨범
·
프로그래머스
https://school.programmers.co.kr/learn/courses/30/lessons/42579 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.krdef solution(genres, plays): # 고유번호가 인덱스인 노래장르 / 각각 재생된 횟수 ''' plays가 가장 높은 장르먼저 그중에서도 가장 높은 plays 노래 그중에서도 재생횟수 같으면 고유번호가 낮은거 장르별로 노래 두개씩 고르기 순서대로 출력 리스트1 = [[전체 플레이 횟수, [재생1위인덱스, 플레이수], [재생2위인덱스, 플레이수]], [...]...] 리스..