128. Longest Consecutive Sequence

Two pass ```python class Solution: def longestConsecutive(self, nums: List[int]) -> int: # time O(N) space O(N) # step1: create a hashset and put num into set # step2: loop through nums, check each num’s neighbour if left neighbour not in the set(means num may be beginning of the sequence) #... [Read More]

859. Buddy Strings

```python class Solution: time O(N) space O(N) def buddyStrings(self, A: str, B: str) -> bool: #early termination: len_a != len_b if len(A) != len(B): return False # case1: A == B if A == B and len(A) > len(set(A)): print('here') return True # case2: A != B, be careful there... [Read More]
Tags: String

449. Serialize and Deserialize BST

be careful with local variable scope ```python Definition for a binary tree node. class TreeNode: def init(self, x): self.val = x self.left = None self.right = None ””” main idea: for serialize , do preorder; for deserilize, use queue to update upper bound and lower bound to detemine if current... [Read More]
Tags: Tree