알고리즘 (12) 썸네일형 리스트형 프로그래머스 단어 변환 (파이썬, DFS) def possible_word(word, words): result = [] for i in words: cnt = 0 if len(word) == len(i): for a, b in zip(word, i): if a != b: cnt += 1 if cnt == 1: result.append(i) return result def solution(begin, target, words): answer = 0 possible = [] def dfs(depth, word, remaining): remain = remaining.copy() if depth >= len(words): return elif word == target: possible.append(depth) else: pos = possible_.. 프로그래머스 - 다리를 지나가는 트럭 (파이썬) 123456789101112131415161718192021def solution(bridge_length, weight, truck_weights): stack = [] success = [] current_weight = 0 cnt = 0 while True: if success and not stack and not current_weight: break for i in range(len([j for j in stack])): stack[i][1] += 1 for i in [j for j in stack if j[1] > bridge_length]: current_weight -= i[0] success.append(i[0]) stack.remove(i) try: if weight - current.. 프로그래머스 체육복 - 파이썬 (탐욕법) 1234567891011121314151617181920def solution(n, lost, reserve): answer = n for i in [j for j in lost[::-1]]: if i in reserve: reserve.remove(i) lost.remove(i) continue elif i - 1 not in reserve and i + 1 not in reserve and i not in reserve: continue elif i - 1 in reserve or i + 1 in reserve or i in reserve: if i - 1 in reserve and i + 1 in reserve: if i - 1 in lost and i + 1 in lost: continue eli.. 프로그래머스 크레인 인형뽑기 게임 - 2019 카카오 개발자 겨울 인턴십 ( 파이썬 ) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 def solution(board, moves): answer = 0 last_basket_num = -1 basket = [-1] for i in moves: layer = 0 if board[-1][i-1] == 0: continue for j in range(len(board)): if board[j][i - 1] != 0: layer = j break if board[layer][i - 1] == last_basket_num: del basket[-1] answer += 2 else: basket.append(board[layer][i-1]) last_basket_num = basket[-1] board[layer][.. 프로그래머스 문자열 압축 - 2020 KAKAO BLIND RECRUITMENT (파이썬) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 def slice_str(s, n): return [s[i:i+n] for i in range(0, len(s), n)] def solution(s): if len(s) == 1: return 1 answer_list = [] for i in range(1, len(s)//2 + 1): sliced_str = slice_str(s, i) count = 1 result_str = "" for j in range(len(sliced_str)): if j 프로그래머스 튜플 - 2019 카카오 개발자 겨울 인턴십 (파이썬) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 def solution(s): answer = [] overlap_dict = dict() s_list = s[1:-1].split("},") for i in range(len(s_list)): s_list[i] = s_list[i].replace("}", "").replace("{", "") s_list[i] = s_list[i].split(",") for i in s_list: for j in i: if overlap_dict.get(j): overlap_dict[j] += 1 else: overlap_dict[j] = 1 sorted_overlap_dict = sorted(overlap_dict.items(), key= lambda x.. 프로그래머스 오픈채팅방 - 2019 KAKAO BLIND RECRUITMENT (파이썬) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 def solution(record): answer = [] name_dict = dict() action_list = [] for i in record: record_list = i.split() if record_list[0] == "Enter": action_list.append("Enter,"+record_list[1]) name_dict[record_list[1]] = record_list[2] elif record_list[0] == "Change": name_dict[record_list[1]] = record_list[2] elif record_list[0] == "Leave": action_list.append("Lea.. 프로그래머스 가운데 글자 가져오기 (파이썬) 1 def solution(s): return s[len(s) // 2] if len(s) % 2 == 1 else s[len(s) // 2 - 1: len(s) // 2 + 1] cs 한줄로 끝냈다. 이전 1 2 다음