Problem Solving/LeetCode(27)
-
Leetcode 104. Maximum Depth of Binary Tree
Leetcode 104. Maximum Depth of Binary Tree https://leetcode.com/problems/maximum-depth-of-binary-tree/ Maximum Depth of Binary Tree - 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 Logic BFS구현(Python) 처음엔 보통 bfs 처럼 while문을 돌고 depth를 하나씩 늘려줬는데 while queue: depth += 1 cur = queue.po..
2021.02.08 -
Leetcode 46. Permutations
Leetcode 46. Permutations Permutations - LeetCode Permutations - 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 Logic DFS로 깊이탐색 prev는 추가되고 next는 줄어들면서 dfs를 돈다 Solution from typing import List class Solution: def permute(self, nums: List[int]) -> List[List[int]]: prev = [] answer =..
2021.01.29 -
[Leetcode] 347. Top K Frequent Elements
Leetcode 347. Top K Frequent Elements https://leetcode.com/problems/top-k-frequent-elements/ 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 Solution 1 collections.Counter() 이용한 풀이. most_common()메소드를 사용했다. collections.Counter() import collections from typi..
2021.01.26 -
[Leetcode] 771. Jewels and Stones
Leetcode 771. Jewels and Stones (3) Jewels and Stones - LeetCode Jewels and Stones - 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 Solution 1 리스트와 파이썬의 if x in y문법을 이용한 풀이. class Solution: def numJewelsInStones(self, jewels: str, stones: str) -> int: count = 0 J = ' '.join(jewels..
2021.01.19 -
[Leetcode] 706. Design HashMap
Leetcode 706.Design HashMap https://leetcode.com/problems/design-hashmap/ Design HashMap - 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 Solution 파이썬의 대표적인 해시형 자료형인 딕셔너리이용 class MyHashMap: def __init__(self): self.dict = {} def put(self, key: int, value: int) -> None: self.dict[k..
2021.01.19 -
[Leetcode] 641. Design Circular Deque
Leetcode 641. Design Circular Deque https://leetcode.com/problems/design-circular-deque/ Design Circular Deque - 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 Solution class MyCircularDeque: def __init__(self, k: int): self.q = [None] * (k+1) self.max = k+1 self.front = 0 self.re..
2021.01.19