반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- yum install java
- mysql executequery error
- statement.executequery() cannot issue statements that do not produce result sets.
- parse
- springboot
- ssl프로토콜확인
- java 여러개 버전
- Medium
- ssl이란?
- No tests found for given includes
- easy
- java 11
- Java 1.8
- 스프링부트테스트
- java version
- LeetCode
- springboottest
- mac os git error
- java 1.8 11
- log error
- java 버전 변경
- AWS CLI
- xcrun: error: invalid active developer path
- java
- OpenFeign
- tls프로토콜확인
- xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools)
- aws
- error
- JUnit
Archives
- Today
- Total
쩨이엠 개발 블로그
[ Leetcode ] 1480. Running Sum of 1d Array - Java 본문
728x90
반응형
Given an array nums. We define a running sum of an array as runningSum[i] = sum(nums[0]…nums[i]).
Return the running sum of nums.
Example 1:
Input: nums = [1,2,3,4]
Output: [1,3,6,10]
Explanation: Running sum is obtained as follows: [1, 1+2, 1+2+3, 1+2+3+4].
Example 2:
Input: nums = [1,1,1,1,1]
Output: [1,2,3,4,5]
Explanation: Running sum is obtained as follows: [1, 1+1, 1+1+1, 1+1+1+1, 1+1+1+1+1].
Example 3:
Input: nums = [3,1,2,10,1]
Output: [3,4,6,16,17]
Constraints:
- 1 <= nums.length <= 1000
- -10^6 <= nums[i] <= 10^6
class Solution {
public int[] runningSum(int[] nums) {
int length = nums.length;
int[] sumNums = new int[length];
for(int i=0; i< length; i++){
for(int j=i; j< length;j++){
sumNums[j] += nums[i];
}
}
return sumNums;
}
}
여기서 어떻게 더 속도를 빠르게 할지는 고민을 좀 해봐야겠다
++ 100%!
class Solution {
public int[] runningSum(int[] nums) {
for(int i=0; i < nums.length-1; i++) {
nums[i+1] += nums[i];
}
return nums;
}
}
728x90
반응형
'개발 > Programming' 카테고리의 다른 글
[ Leetcode ] 214. Shortest Palindrome - Java (0) | 2021.01.28 |
---|---|
[ Leetcode ] 162. Find Peak Element - Java (0) | 2021.01.28 |
[ Leetcode ] 1431. Kids With the Greatest Number of Candies - Java (0) | 2021.01.27 |
[ Leetcode ] 28. Implement strStr() - Java (0) | 2021.01.27 |
[ Leetcode ] 66. Plus One - Java (0) | 2021.01.26 |
Comments