LC763 Partition Labels

```python class Solution: # time O(N) where N=26 ~ O(1) space O(1) “”” main idea: for each char, store their last appeared index, then loop through each char,keep updating biggest last index, and check if any of them has reached biggest last index so far. """ def partitionLabels(self, S: str)... [Read More]

LC679 24 Game

```python class Solution: def judgePoint24(self, nums: List[int]) -> bool: if not nums: return False def helper(nums): # step1, base: only one card/ number left and it equals to 24, return True, otherwise return False size = len(nums) if size == 1:return abs(nums[0]-24) < 1e-6 # step2: brute force to find... [Read More]
Tags: DFS

LC17 Letter Combinations of a Phone Number

```python class Solution: def letterCombinations(self, digits: str) -> List[str]: “”” main idea: typical backtracking problem to choose all char in first digit while track remaining substring. step0: edge case: if digits is “” return immediately step1, cache all characters corresponding to digit and set res [] step2, termination check: when... [Read More]

LC93 Restore IP Addresses

```python class Solution: “”” step1, set limit for 4 level recursion and stop; check if all string are used, if yes, push into result. otherwise ignore. return current path step2, set substring length limit: 1-3. and discuss number restrictions based on length variety. (len== 1: no restriction; len ==2: first... [Read More]