Tech Cow

Results 32 comments of Tech Cow

优化1. Brute Force的冗余,通过Pruning去省去一些重复计算。 思考的方式可以从需要最少被更改几次出发 计算出左右括号的个数差,然后用函数 `change_needed` 表示。 在Backtrack过程中,往temp里面增加元素的时候不需要更改这个函数,因为并没有删除任何函数,而在删减的过程中,减少这个函数。 这种方式可以对change_needed为负数的时候进行剪枝 ```python if change_needed < 0: return ``` 然后对左右括号和其他字符的区分,也进行了一边的剪枝。 ### 优化代码 ```python class Solution(): def removeInvalidParentheses(self, s): left = right = change_needed...

优化2: 把Temp的Array 变成了 String,减少了一些代码和速度 ```python class Solution(): def removeInvalidParentheses(self, s): left = right = change_needed = 0 for char in s: if char == '(': left += 1 elif char...

```python class Solution: def removeInvalidParentheses(self, s: str) -> List[str]: left = right = 0 for c in s: if c == "(": left += 1 elif c == ")": if...

```python ''' Start: 6:59 # @ [二刷] Bug 1: findLeftRightDiff() takes exactly 1 arguement @ Bug def findLeftRightDiff(s): @ Fixed def findLeftRightDiff(self, s): Bug 2: @ Bug else: self.dfsHelper(s, res,...

## Week 2 | Day 2 ### Goal * Focus on High Freq Qs ### Leetcode #### 29. Divide Two Integers (x3) - [ ] 29. Divide Two Integers >...

## Week 2 | Day 3 ### Goal * Focus on High Freq Qs ### Leetcode - [ ] Next Permutation (x2) - [ ] 426. Convert Binary Search Tree...

## Week 2 | Day 4 ### Goal * All Trees ### Leetcode - [ ] 230. Kth Smallest Element in a BST - 如果n是已知的一个不变的数字,能否略过某些步骤? - 如果树是满的,能否略过某些步骤? - [ ]...

## Week 2 | Day 5 ### Goal * All Graph ### Leetcode - Regular - [ ] 133. Clone Graph - What about Directed Graph? - Matrix - [...

## Week 2 | Day 6 ### Goal #### DFS / Backtracking ### Leetcode - [x] 301 Remove Invalid Parentheses - [x] 78. Subsets - [x] 567. Permutation in String...

sliding window problems: 76,438, 567