Skip to content

Commit e521e15

Browse files
authored
Merge pull request #1079 from AlgorithmWithGod/LiiNi-coder
[20251009] PGM / LV2 / 숫자의 표현 / 이인희
2 parents ec30369 + 83478f0 commit e521e15

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
```java
2+
class Solution {
3+
public int solution(int n) {
4+
int[] sum = new int[n + 1];
5+
for(int i=1; i<=n; i++)
6+
sum[i] = sum[i-1] + i;
7+
8+
int l = 0, r = 1, answer = 0;
9+
while(l < r && r <= n){
10+
int now = sum[r] - sum[l];
11+
if(now == n){
12+
answer++;
13+
r++;
14+
}else if(now < n)
15+
r++;
16+
else
17+
l++;
18+
}
19+
20+
return answer;
21+
}
22+
}
23+
```

0 commit comments

Comments
 (0)