GeezerVison is showing github.com — 1480_Running_Sum_of_1d_Array · iamsathish/leetcode@3bc1561
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: README.md +1Lines changed: 1 addition & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -224,6 +224,7 @@ I'm currently working on [Analytics-Zoo](https://github.com/intel-analytics/anal |
224 | 224 | | 1260 | [Shift 2D Grid](https://leetcode.com/problems/shift-2d-grid/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/1260_Shift_2D_Grid.py) [Java](https://github.com/qiyuangong/leetcode/blob/master/java/1260_Shift_2D_Grid.java) | Final position of each element can be computed according to k, m and n, e.g., k == mn, then don't move, O(mn) and O(mn) | |
225 | 225 | | 1337 | [The K Weakest Rows in a Matrix](https://leetcode.com/problems/the-k-weakest-rows-in-a-matrix/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/1337_The_K_Weakest_Rows_in_a_Matrix.py) [Java](https://github.com/qiyuangong/leetcode/blob/master/java/1337_The_K_Weakest_Rows_in_a_Matrix.java) | Check by row, from left to right, until encount first zero, O(mn) and O(1) | |
226 | 226 | | 1365 | [How Many Numbers Are Smaller Than the Current Number](https://leetcode.com/problems/how-many-numbers-are-smaller-than-the-current-number/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/1365_How_Many_Numbers_Are_Smaller_Than_the_Current_Number.py) [Java](https://github.com/qiyuangong/leetcode/blob/master/java/1365_How_Many_Numbers_Are_Smaller_Than_the_Current_Number.java) | 1. Sort and get position in sorted nums, O(nlogn) and O(n)<br>2. Fill count into 0-100, O(n) and O(1) | |
| 227 | +| 1480 | [Running Sum of 1d Array](https://leetcode.com/problems/running-sum-of-1d-array/) | [Python](https://github.com/qiyuangong/leetcode/blob/master/python/1480_Running_Sum_of_1d_Array.py) [Java](https://github.com/qiyuangong/leetcode/blob/master/java/1480_Running_Sum_of_1d_Array.java) | 1. Go through the array, O(n) and O(1)<br>2. Accumulate API | |
227 | 228 |
|
228 | 229 | | # | To Understand | |
229 | 230 | |---| ----- | |
|
Collapse file
Copy file name to clipboard +11Lines changed: 11 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +class Solution { |
| 2 | + public int[] runningSum(int[] nums) { |
| 3 | + if (nums.length <= 1) return nums; |
| 4 | + int accu = nums[0]; |
| 5 | + for (int i = 1; i < nums.length; i++) { |
| 6 | + accu += nums[i]; |
| 7 | + nums[i] = accu; |
| 8 | + } |
| 9 | + return nums; |
| 10 | + } |
| 11 | +} |
Collapse file
Copy file name to clipboard +11Lines changed: 11 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +class Solution: |
| 2 | + def runningSum(self, nums: List[int]) -> List[int]: |
| 3 | + if nums is None or len(nums) == 0: |
| 4 | + return nums |
| 5 | + for i in range(1, len(nums)): |
| 6 | + nums[i] += nums[i-1] |
| 7 | + return nums |
| 8 | + |
| 9 | + # def runningSum(self, nums: List[int]) -> List[int]: |
| 10 | + # # accumulate method |
| 11 | + # return accumulate(nums) |