defaultdict2 [자료구조] 배달 파이썬 (BFS, queue, Dijkstra, heap) from math import inf from collections import defaultdict, deque from itertools import product def solution(N, roads, K): answer = [inf, 0] + [inf for i in range(N-1)] # print(answer) # why 처음이 0이 아니라 inf로 설정했을까? -> zero 인덱스 문제를 편하게 하려고 map = defaultdict(list) # 리스트 형태로 받겠다. dist_map = [[inf for _ in range(N+1)] for _ in range(N+1)] # print(dist_map) # for road in roads: a,b,dist = road map[a].ap.. 2021. 4. 23. [LeetCode] Ransom Note 파이썬 (dict, set, count) from collections import defaultdict class Solution: def canConstruct(self, ransomNote: str, magazine: str) -> bool: seen = defaultdict(int) for r in ransomNote: seen[r] += 1 for m in magazine: if m in seen: seen[m] -= 1 for v in seen.values(): if v > 0: return False return True "fihjjjjei" "hjibagacbhadfaefdjaeaebgi" defaultdict(, {'f': -1, 'i': 0, 'h': -1, 'j': 2, 'e': -2}) seen 이라는 dict에 0보다 큰.. 2021. 4. 14. 이전 1 다음