Skip to content

Commit 3ebae0b

Browse files
authored
Merge pull request #1421 from AlgorithmWithGod/0224LJH
[20251116] PGM / LV2 / 연속 부분 수열 / 이종환
2 parents 10b904f + 2936c48 commit 3ebae0b

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
class Solution {
6+
7+
static HashSet<Integer> set = new HashSet<>();
8+
9+
10+
public int solution(int[] elements) {
11+
int len = elements.length;
12+
13+
for (int i = 1; i <= len; i++){
14+
int curLen = i;
15+
16+
int curSum = 0;
17+
for (int j = 0; j < curLen; j++){
18+
curSum += elements[j];
19+
}
20+
21+
int st = 0;
22+
int end = curLen-1;
23+
set.add(curSum);
24+
25+
for (int j = 1; j < len; j++){
26+
curSum -= elements[st];
27+
st++;
28+
end++;
29+
end %= len;
30+
curSum += elements[end];
31+
32+
set.add(curSum);
33+
}
34+
35+
}
36+
37+
38+
int answer = set.size();
39+
return answer;
40+
}
41+
}
42+
```

0 commit comments

Comments
 (0)