8000 solved 1480 Β· realtemirov/leetcode@3350c75 Β· GitHub
[go: up one dir, main page]

Skip to content

Commit 3350c75

Browse files
committed
solved 1480
1 parent 9c569d5 commit 3350c75

7 files changed

+74
-46
lines changed

β€ŽProblems/1480. Running Sum of 1d Array.md

Lines changed: 0 additions & 43 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# 1480. Running Sum of 1d Array
2+
3+
🟩 Easy
4+
5+
## Solution
6+
7+
My Solution
8+
9+
```go
10+
func runningSum(nums []int) []int {
11+
for i:=1; i<len(nums); i++ {
12+
nums[i] += nums[i-1]
13+
}
14+
15+
return nums
16+
}
17+
```
18+
19+
![result](1480.png)
20+
21+
Leetcode: [link](https://leetcode.com/problems/running-sum-of-1d-array/description/)

β€ŽProblems/1480/1480.png

34.6 KB
Loading

β€ŽProblems/1480/solution.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package problem1480
2+
3+
func RunningSum(nums []int) []int {
4+
for i:=1; i<len(nums); i++ {
5+
nums[i] += nums[i-1]
6+
}
7+
8+
return nums
9+
}

β€ŽProblems/1480/solution_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package problem1480_test
2+
3+
import (
4+
"testing"
5+
6+
problem1480 "github.com/realtemirov/leetcode/Problems/1480"
7+
"github.com/stretchr/testify/require"
8+
)
9+
10+
func TestSolution(t *testing.T) {
11+
testCases := []struct {
12+
name string
13+
cases []int
14+
expected []int
15+
}{
16+
{
17+
name: "Test 1",
18+
cases: []int{1, 2, 3, 4},
19+
expected: []int{1, 3, 6, 10},
20+
},
21+
{
22+
name: "Test 2",
23+
cases: []int{1, 1, 1, 1, 1},
24+
expected: []int{1, 2, 3, 4, 5},
25+
},
26+
{
27+
name: "Test 3",
28+
cases: []int{3, 1, 2, 10, 1},
29+
expected: []int{3, 4, 6, 16, 17},
30+
},
31+
}
32+
33+
for _, tc := range testCases {
34+
t.Run(tc.name, func(t *testing.T) {
35+
result := problem1480.RunningSum(tc.cases)
36+
require.Equal(t, tc.expected, result, "expected: %v, result: %v", tc.expected, result)
37+
})
38+
}
39+
}

β€ŽProblems/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Problems
22

3-
> **Total:** `70` \
4-
> **Easy:** `48` \
3+
> **Total:** `71` \
4+
> **Easy:** `49` \
55
> **Medium:** `22` \
66
> **Hard:** `0`
77
@@ -59,6 +59,7 @@
5959
* 🟧 Medium - [1041. Robot Bounded In Circle](<./1041/1041. Robot Bounded In Circle.md>)
6060
* 🟩 Easy - [1232. Check If It Is a Straight Line](<./1232/1232. Check If It Is a Straight Line.md>)
6161
* 🟩 Easy - [1275. Find Winner on a Tic Tac Toe Game](<./1275/1275. Find Winner on a Tic Tac Toe Game.md>)
62+
* 🟩 Easy - [1480. Running Sum of 1d Array](<./1480/1480. Running Sum of 1d Array.md>)
6263
* 🟩 Easy - [1491. Average Salary Excluding the Minimum and Maximum Salary](<./1491/1491. Average Salary Excluding the Minimum and Maximum Salary.md>)
6364
* 🟩 Easy - [1502. Can Make Arithmetic Progression From Sequence](<./1502/1502. Can Make Arithmetic Progression From Sequence.md>)
6465
* 🟩 Easy - [1523. Count Odd Numbers in an Interval Range](<./1523/1523. Count Odd Numbers in an Interval Range.md>)

β€ŽSUMMARY.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
* [1041. Robot Bounded In Circle](<./Problems/1041/1041. Robot Bounded In Circle.md>)
115115
* [1232. Check If It Is a Straight Line](<./Problems/1232/1232. Check If It Is a Straight Line.md>)
116116
* [1275. Find Winner on a Tic Tac Toe Game](<./Problems/1275/1275. Find Winner on a Tic Tac Toe Game.md>)
117+
* [1480. Running Sum of 1d Array](<./Problems/1480/1480. Running Sum of 1d Array.md>)
117118
* [1491. Average Salary Excluding the Minimum and Maximum Salary](<./Problems/1491/1491. Average Salary Excluding the Minimum and Maximum Salary.md>)
118119
* [1502. Can Make Arithmetic Progression From Sequence](<./Problems/1502/1502. Can Make Arithmetic Progression From Sequence.md>)
119120
* [1523. Count Odd Numbers in an Interval Range](<./Problems/1523/1523. Count Odd Numbers in an Interval Range.md>)
@@ -216,7 +217,7 @@
216217
* [1431. Kids With the Greatest Number of Candies](<Problems/1431. Kids With the Greatest Number of Candies.md>)
217218
* [1436. Destination City](<Problems/1436. Destination City.md>)
218219
* [1464. Maximum Product of Two Elements in an Array](<Problems/1464. Maximum Product of Two Elements in an Array.md>)
219-
* [1480. Running Sum of 1d Array](<Problems/1480. Running Sum of 1d Array.md>)
220+
220221
* [1496. Path Crossing](<Problems/1496. Path Crossing.md>)
221222
* [1551. Minimum Operations to Make Array Equal](<Problems/1551. Minimum Operations to Make Array Equal.md>)
222223
* [1582. Special Positions in a Binary Matrix](<Problems/1582. Special Positions in a Binary Matrix.md>)

0 commit comments

Comments
Β (0)
0