Binary Tree Level Order Traversal - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 1. Queue를 사용한 풀이 class Solution: def levelOrder(self, root: TreeNode) -> List[List[int]]: answer = [] if not root: return [] q = deque([]) q.append((root, 0)) trace = {} while q: cur_node, cur_level..
Combination Sum - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 1. 내 Trash Garbage Code from typing import * # DP로 풀어야할 것 같다 # 완전탐색으로 하면 반드시 TLE가 날 것 같은 문제 # 라고 생각했는데 노트에 써보니깐 백트래킹 문제 같다. class Solution: def combinationSum(self, candidates: List[int], target: int) -> List[List[in..
Group Anagrams - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 1. 소팅된 문자열을 Key로 하는 Dict(HashMap)을 이용한 풀이 class Solution: def groupAnagrams(self, strs: List[str]) -> List[List[str]]: dict1={} for str in strs: temp="".join(sorted(list(str))) if temp not in dict1: dict1[temp]=[str] ..
Rotate Image - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 요약 2차원 배열이 주어지면 추가 공간 할당 없이 시계 방향으로 회전시키는 문제 1. Swap class Solution: def rotate(self, matrix: List[List[int]]) -> None: length = len(matrix) for i in range(length // 2 + length % 2): for j in range(length // 2): temp = ..
Top K Frequent Elements - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 1. Using Counter from typing import * from collections import Counter class Solution: def topKFrequent(self, nums: List[int], k: int) -> List[int]: counter_dict = Counter() for num in nums: counter_dict[num] ..
Palindromic Substrings - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 1. Brute Force (실패) class Solution: def countSubstrings(self, s: str) -> int: def check(input_string): start, end = 0, len(input_string) - 1 while start < end: if input_string[start] != input_string[end]: retu..