Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit656c1a0

Browse files
authored
Refactored Running Sum of 1d Array.java
1 parent588a3e1 commit656c1a0

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

‎Easy/Running Sum of 1d Array.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
classSolution {
22
publicint[]runningSum(int[]nums) {
33
int[]ans =newint[nums.length];
4-
intsum =0;
54
for (inti =0;i <nums.length;i++) {
6-
sum +=nums[i];
7-
ans[i] =sum;
5+
ans[i] =nums[i] + (i ==0 ?0 :ans[i -1]);
86
}
97
returnans;
108
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp