Skip to content

Commit f748e00

Browse files
committed
solution 1480 by java
1 parent cf3e038 commit f748e00

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/main/java/Solution1480.java

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import java.util.Arrays;
2+
3+
/**
4+
* LC#1480:一维数组动态和
5+
* Link: https://leetcode-cn.com/problems/running-sum-of-1d-array/
6+
* 思路:动态规划 DP 普通题
7+
* @author Phoenix on 2021/5/29.
8+
*/
9+
public class Solution1480 {
10+
11+
public static int[] runningSum(int[] nums) {
12+
int lastValue = 0;
13+
for (int i = 0; i < nums.length; i++) {
14+
lastValue += nums[i];
15+
nums[i] = lastValue;
16+
}
17+
return nums;
18+
}
19+
20+
public static void main(String[] args) {
21+
int[] nums = {1, 2, 3, 4};
22+
System.out.println(Arrays.toString(runningSum(nums)));
23+
}
24+
25+
}

0 commit comments

Comments
 (0)