Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdf01d14

Browse files
authored
Create 3.java
1 parent7ad989b commitdf01d14

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

‎20/3.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
importjava.util.*;
2+
3+
classMain {
4+
publicstaticintn =5;// 데이터의 개수 N
5+
publicstaticintm =5;// 찾고자 하는 부분합 M
6+
publicstaticint[]arr = {1,2,3,2,5};// 전체 수열
7+
8+
publicstaticvoidmain(String[]args) {
9+
intcnt =0;
10+
intintervalSum =0;
11+
intend =0;
12+
13+
// start를 차례대로 증가시키며 반복
14+
for (intstart =0;start <n;start++) {
15+
// end를 가능한 만큼 이동시키기
16+
while (intervalSum <m &&end <n) {
17+
intervalSum +=arr[end];
18+
end +=1;
19+
}
20+
// 부분합이 m일 때 카운트 증가
21+
if (intervalSum ==m) {
22+
cnt +=1;
23+
}
24+
intervalSum -=arr[start];
25+
}
26+
27+
System.out.println(cnt);
28+
}
29+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp