🧑💻 Coding Test/Hash Table17 [Programmers] 베스트앨범 시작하기 전에프로그래머스 알고리즘 고득점 Kit에서 해시 단원의 마지막 문제입니다.I. DescriptionII. Codedef solution(genres, plays): genre_dict = {} genre_play_dict = {} answer = [] # 장르별 재생 횟수 딕셔너리 생성 ({'classic': 1450, 'pop': 3100}) for i in range(len(genres)): genre_dict[genres[i]] = genre_dict.get(genres[i], 0) + plays[i] # 재생 횟수 기준 내림차순으로 정렬 (['pop', 'classic']) sorted_genres = [k for k.. 2025. 7. 1. [Programmers] 의상 시작하기 전에프로그래머스 알고리즘 고득점 Kit에서 해시 단원의 네 번째 문제입니다.I. DescriptionII. Codedef solution(clothes): clothes_dict = {} answer = 1 for cloth in clothes: clothes_dict[cloth[1]] = clothes_dict.get(cloth[1], 0) + 1 for num in clothes_dict.values(): answer *= (num+1) answer -= 1 return answer# Test casesif __name__ == "__main__": clothes_list = [[["yellow_hat.. 2025. 7. 1. [Programmers] 전화번호 목록 시작하기 전에프로그래머스 알고리즘 고득점 Kit에서 해시 단원의 세 번째 문제입니다.I. DescriptionII. Codedef solution(phone_book): phone_dict = {} # 전화번호부의 각 전화번호를 키로 하는 딕셔너리 생성 for phone in phone_book: phone_dict[phone] = 1 # 각 전화번호의 접두사가 전화번호부에 있는지 확인 for phone in phone_book: tmp = "" for digit in phone[:-1]: tmp += digit if tmp in phone_dict.keys(): .. 2025. 6. 30. [Programmers] 폰켓몬 시작하기 전에프로그래머스 알고리즘 고득점 Kit에서 해시 단원의 두 번째 문제입니다.I. DescriptionII. Codedef solution(nums): pocket_dict = {} # {'포켓몬 번호': '포켓몬 개수'} 형태의 딕셔너리 생성 for num in nums: pocket_dict[num] = pocket_dict.get(num, 0) + 1 # 포켓몬 종류의 개수가 전체 개수의 절반보다 작거나 같으면 그 개수를 반환 return min(len(pocket_dict), len(nums) // 2)# Test casesif __name__ == "__main__": nums_list = [[3, 1, 2, 3], [3, 3, .. 2025. 6. 29. [Programmers] 완주하지 못한 선수 시작하기 전에프로그래머스 알고리즘 고득점 Kit에서 해시 단원의 첫 번째 문제입니다.I. DescriptionII. Codedef solution(participant, completion): player_dict = {} # {'선수명': '해당 선수명의 완주하지 못한 선수 수'} for part in participant: player_dict[part] = player_dict.get(part, 0) + 1 for comp in completion: player_dict[comp] -= 1 for key, value in player_dict.items(): if value == 1: return ke.. 2025. 6. 29. [LeetCode] 36. Valid Sudoku I. DescriptionII. Codeclass Solution: def isValidSudoku(self, board: List[List[str]]) -> bool: # 가로 중복 체크 for row in board: for i in row: if i != '.' and row.count(i) > 1: return False # 세로 중복 체크 for i in range(9): col = [row[i] for row in board] for j in col: if j != '.' and col.coun.. 2025. 1. 25. [LeetCode] 17. Letter Combinations of a Phone Number I. DescriptionII. Codeclass Solution: def letterCombinations(self, digits: str) -> List[str]: dict = {'2': 'abc', '3': 'def', '4': 'ghi', '5': 'jkl', '6': 'mno', '7': 'pqrs', '8': 'tuv', '9': 'wxyz'} result = [] for digit in digits: if not result: result = [i for i in dict[digit]] else: temp = result.copy() .. 2025. 1. 25. [LeetCode] 12. Integer to Roman I. DescriptionII. Codeclass Solution: def intToRoman(self, num: int) -> str: res = 'M' * (num // 1000) num %= 1000 val = num // 100 if val == 9: res += 'CM' elif val == 4: res += 'CD' else: res += 'D' * (val // 5) + 'C' * (val % 5) num %= 100 val = num // 10 if val == 9: .. 2025. 1. 25. 이전 1 2 3 다음