```python class Solution: def countLetters(self, s: str) -> int: “”” tc O(N) sc O(N) main idea: sliding window. number of substring can be caculated by accumutive sum of count at each iteration “”” d = {} l = 0 res = 0 for r in range(len(s)): if s[r] not in...
[Read More]
214. Shortest Palindrome
class Solution:
def shortestPalindrome(self, s: str) -> str:
rev = s[::-1]
n = len(s)
for i in range(n):
if s[0:n-i] == rev[i:]: # longest prefix substring which is palindrom
return rev[0:i]+s
return ""
[Read More]
362. Design Hit Counter
Brute Force: Queue
```python
class HitCounter:
def __init__(self):
self.q = collections.deque()
[Read More]
510. Inorder Successor in BST II
```python
“””
Definition for a Node.
class Node:
def init(self, val):
self.val = val
self.left = None
self.right = None
self.parent = None
“””
[Read More]
45. Jump Game II
""" main idea: use right_most to record longest distance within current choice range. since our start point is confirmed, we need to create a end point to mark that the moment is time to move to next step end at furtherest distance. Note here we do not need to go...
[Read More]