leetcode
leetcode copied to clipboard
👏🏻 leetcode solutions for Humans™
Try 2: Bug Free ```python from collections import deque class Codec: def serialize(self, root): if not root: return "" res = [] queue = deque([root]) while queue: node = queue.popleft()...
Redo Binary Search, has bug #### 349. Intersection of Two Arrays ```python class Solution(object): def intersection(self, nums1, nums2): nums1 = set(nums1) nums2 = set(nums2) res = [] for num in...
```python class Solution: def longestArithSeqLength(self, A: List[int]) -> int: if not A or len(A) == 1: return 0 dic = {} for i in range(1, len(A)): for j in range(i):...
### 第一刷 ```python ''' Bug 1: 这里如果 == base case底端,很多过程中的case都不会被记录 if index == len(nums) and len(temp) >= 2: 疑问: 为什么会有[4,7,7]这个output,set不会把第二个7去重么? 答: 每层递归的都会开一次新的set,而不是globalSet。所以只会针对当前层的duplicate 比如arr = [4,7,7] arr[1]是第二层的 arr[2]是第三层的,到达第三层的时候,新开辟的set里面不会有第二层的7 ''' class Solution(object):...
### 973. K Closest Points to Origin #### Problem Solving  -----  #### Buggy Code ```python from heapq import heapreplace, heapify class Solution(object): def kClosest(self, pairs, k): nums =...
```python ''' start[6:12] Problem Solving: [?] Sliding window algorithm * Potentially scan through with 2 pointers - left being the window shrinker - right being the window extender extend right...
```python ''' [8:41] Start Thoughts (Didn't execute since not sure?): Use a stack, and looking @ elements from the end Having a hashmap { key | val reverse index of...