```python “”” clockwise rotate first reverse up to down, then swap the symmetry 1 2 3 7 8 9 7 4 1 4 5 6 => 4 5 6 => 8 5 2 7 8 9 1 2 3 9 6 3 */””” class Solution: def rotate(self, matrix: List[List[int]]) ->...
[Read More]
LC57 Insert Interval
Naive solution
[Read More]
CandyCrush1D
refer ```python “”” main idea: loop through each char and count char that is same in the row, until encounter a different char, store previous char and cnt into stack; then check if candies can be crushed by checking top of stack, if yes, crush candies first before push new...
[Read More]
LC218 The Skyline Problem
from heapq import heappush, heappop class Solution: # time O(NlgN) since 1.sort 2. heap push pop ops cost lgN each time. space O(N) to maintain heap and events def getSkyline(self, buildings: List[List[int]]) -> List[List[int]]: events_s = [(L,-H, R) for L,R,H in buildings] # remove same endpoint events events_e = list({(R,0,0)...
[Read More]
LC165 Compare Version Numbers
class Solution: def compareVersion(self, version1: str, version2: str) -> int: """ step1: split '.' out of str and convert each segment into integer to remove leading 0 s and then save them to [] step2: find max length of the two lists. start loop each list step3: get current segment...
[Read More]