Tech Cow
                                            Tech Cow
                                        
                                    ### 1146. Snapshot Array #### Brute Force | Memory Limit Exceeded Memory usage needs to be more efficient. In this code snippet, too many unused `0` element were stored in...
第一次刷 1. 常犯错:Parameter Passing的时候经常忘记加东西 2. 是len(board) 而不是 len(word), 再有多个参考参数的时候,要注意分辨。。 3. 最好不要用slice ```python class Solution(object): def exist(self, board, word): if not board: return False # No need for i in range(len(board)):...
### Working Code (使用Visited) 这里学到一招记录二维数组里面的Visited Elements: 这种方式消费了额外空间,但是不对原Input `board`进行修改。 ### 时间复杂度  遍历所有的元素需要 m * n, 在每个元素使用一次DFS, 有4个方向(对应Recursion Tree里面的4个Branches,然后树的高度为k) 所以总共 `O(m * n * 4^k)` ```python class Solution(object): def exist(self, board,...
### Working Code (不使用Visited) ```python class Solution(object): def exist(self, board, word): for i in range(len(board)): for j in range(len(board[0])): if self.dfsHelper(board, i , j, word, 0): return True return False...
### 209. Minimum Size Subarray Sum ```python class Solution(object): def minSubArrayLen(self, target, nums): globalMin = float('inf') curSum = 0 j = 0 for i in range(len(nums)): while j < len(nums)...
### 3. Longest Substring Without Repeating Characters ```python class Solution(object): def lengthOfLongestSubstring(self, s): globalMax = -float('inf') globalSet = set() j = 0 for i in range(len(s)): while j < len(s)...
```python class Solution(object): def subarraySum(self, nums, k): res = 0 n = len(nums) for i in range(n): preSum = 0 for j in range(i, n): preSum += nums[j] if preSum...
### 247. Strobogrammatic Number II 通过字典里面的分叉,然后用Two Pointer向内夹紧的方法进行DFS  ```python class Solution(object): def findStrobogrammatic(self, n): res = [] dic = {'0':'0', '1':'1', '6':'9', '8':'8', '9':'6'} self.helper(res, [None] * n, 0, n...
### 200 Number of Islands ```python class Solution(object): def numIslands(self, grid): if not grid: return 0 visited = {} m, n = len(grid), len(grid[0]) res = 0 for i in...
### 53. Maximum Subarray ```python class Solution(object): # Space O(N) def maxSubArray(self, nums): f = [-float('inf')] * len(nums) globalMax = -float('inf') for i, num in enumerate(nums): if f[i - 1]...