https://school.programmers.co.kr/learn/courses/30/lessons/12924
ํฌํฌ์ธํฐ ์๊ณ ๋ฆฌ์ฆ ์ฌ์ฉํ๋ค.
class Solution {
public int solution(int n) {
int answer = 0;
int sum = 0;
int lt = 0;
int[] arr = new int[n];
for(int i=0; i<n; i++) arr[i]=i+1;
for(int rt=0; rt<n; rt++){
sum+=arr[rt];
if(sum==n) answer++;
while(sum>=n){
sum-=arr[lt++];
if(sum==n) answer++;
}
}
return answer;
}
}
'๐ ์ฝ๋ฉํ ์คํธ > ๋ฐฑ์ค & ํ๋ก๊ทธ๋๋จธ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค][JAVA]Level 2 : ํผ๋ณด๋์น ์ (0) | 2023.04.03 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค][JAVA]Level 2 : ๋ค์ ํฐ ์ซ์ (0) | 2023.04.02 |
[ํ๋ก๊ทธ๋๋จธ์ค][JAVA]Level 2 : ์ด์ง ๋ณํ ๋ฐ๋ณตํ๊ธฐ (0) | 2023.03.31 |
[ํ๋ก๊ทธ๋๋จธ์ค][JAVA]Level 2 : ์ฌ๋ฐ๋ฅธ ๊ดํธ (0) | 2023.03.30 |
[ํ๋ก๊ทธ๋๋จธ์ค][JAVA] Level 2 : ์ต์๊ฐ ๋ง๋ค๊ธฐ (0) | 2023.03.27 |