본문 바로가기

Problem-solving119

프로그래머스 - (2019 카카오 개발자 겨울 인턴십) 튜플 (Python) def solution(input_str): # 정답 튜플을 담을 리스트 answer = [] # set형 문자열 input_str을 list화하여 저장할 list list_of_number = [] # input_str집합의 원소들을 문자열로 가지는 리스트로 변환 list_of_str_element_of_input_str = input_str[2:len(input_str) - 2].split("},{") # list_of_str_element_of_input_str의 각 문자열 원소들을 리스트화 for element in list_of_str_element_of_input_str: list_of_number.append(list(map(int, element.split(',')))) # 원소 list의.. 2020. 5. 8.
프로그래머스 - 전화번호 목록 (Python) def solution(phone_book): phone_book.sort() for phone_number_index in range(len(phone_book) - 1): for the_other_phone_number_index in range(phone_number_index + 1, len(phone_book)): if phone_book[the_other_phone_number_index].startswith(phone_book[phone_number_index]): return False return True 2020. 5. 8.
프로그래머스 - 더 맵게 (Python) import heapq def solution(scoville, K): # 기존 리스트를 힙으로 변환 heapq.heapify(scoville) mix_count = 0 while scoville[0] < K: if len(scoville) == 1: return -1 # 가장 맵지 않은 음식의 스코빌 지수와, 두 번째로 맵지 않은 스코빌 지수 꺼냄 lowest_scoville = heapq.heappop(scoville) second_lowest_scoville = heapq.heappop(scoville) # 섞은 음식의 스코빌 지수 생성 new_scoville = lowest_scoville + (second_lowest_scoville * 2) # 섞은 개수 1 증가 mix_count += 1 #.. 2020. 5. 7.
프로그래머스 - 소수 찾기 (Python) from functools import cmp_to_key def compare(first_num_str, second_num_str): first_sum = int(first_num_str + second_num_str) second_sum = int(second_num_str + first_num_str) return second_sum - first_sum def solution(numbers): number_str_list = list(map(str, numbers)) sorted_number_str_list = sorted(number_str_list, key=cmp_to_key(compare)) return str(int(''.join(sorted_number_str_list))) 2020. 5. 7.