Skip to content

Commit 844de3d

Browse files
committed
2017-10-12
1 parent 998c1c7 commit 844de3d

File tree

4 files changed

+45
-6
lines changed

4 files changed

+45
-6
lines changed

5/Readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
# 2017-10-12 풀이 목록
2+
* Two Pointer[코드 보기](twopointer/Main.java)
13
# 2017-10-05 풀이 목록
24
* Sliding Window[코드 보기](slidingwindow/Main.java)

5/slidingwindow/Readme.md

Lines changed: 0 additions & 6 deletions
This file was deleted.

5/twopointer/Main.class

1.54 KB
Binary file not shown.

5/twopointer/Main.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import java.util.*;
2+
import java.io.*;
3+
/**
4+
* Main
5+
*/
6+
public class Main {
7+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
9+
public static void main(String[] args) throws IOException{
10+
11+
String str1[] = br.readLine().split(" ");
12+
13+
int min = Integer.MAX_VALUE;
14+
int sum = 0;
15+
int N = Integer.parseInt(str1[0]), M = Integer.parseInt(str1[1]);
16+
17+
String str2[] = br.readLine().split(" ");
18+
int arr[] = new int[N];
19+
int l=0,r=0;
20+
for(int i = 0; i<N; i++){
21+
arr[i] = Integer.parseInt(str2[i]);
22+
}
23+
sum=arr[0];
24+
while(true){
25+
if(sum<M){
26+
r++;
27+
if(r<N)
28+
sum+=arr[r];
29+
else
30+
break;
31+
}else{
32+
sum -= arr[l];
33+
min = Math.min(min, r-l+1);
34+
l++;
35+
}
36+
}
37+
if(min == Integer.MAX_VALUE)
38+
bw.write("0");
39+
else
40+
bw.write(String.valueOf(min));
41+
bw.flush();
42+
}
43+
}

0 commit comments

Comments
 (0)