문제풀이 2021 01 05
2021.01.05 연습
- 사용언어 : java
class Solution {
public int[] runningSum(int[] nums) {
int[] result = new int[nums.length];
for (int i = 0; i < nums.length; i ++) {
if (i == 0) {
result[0] = nums[0];
} else {
result[i] = nums[i]+result[i-1];
}
}
return result;
}
}
Runtime: 0 ms, faster than 100.00% of Java online submissions for Richest Customer Wealth. Memory Usage: 38.9 MB, less than 36.11% of Java online submissions for Richest Customer Wealth.
- better code
class Solution {
public int[] runningSum(int[] nums) {
for(int i = 1; i < nums.length; i++){
nums[i] += nums[i-1];
}
return nums;
}
}