김찬진의 개발 블로그
[23/09/10] B26042 본문
peek 과 poll 의 차이
peek 은 구조체에서 제거하지 않고 반환
poll 은 구조체에서 제거한 후 반환
package D1;
import java.util.*;
// 막대기
public class B17608 {
public static void main(String[] args) {
Stack<Integer> stack = new Stack<>();
Scanner sc = new Scanner(System.in);
int testCase = sc.nextInt();
int count = 1;
for(int i=0; i<testCase; i++) {
stack.push(sc.nextInt());
}
int popped = stack.pop();
while(!stack.empty()) {
if(stack.peek() > popped) {
count++;
popped = stack.pop();
continue;
}
stack.pop();
}
System.out.println(count);
}
}
'1일1알고 > Java Algorithm' 카테고리의 다른 글
[23/09/10] B9012 (0) | 2023.09.10 |
---|---|
[23/09/10] B12873 (0) | 2023.09.10 |
[23/09/10] B28279 (0) | 2023.09.10 |
[23/05/12] B11053 (0) | 2023.05.12 |
[23/05/12] B2839_DP (0) | 2023.05.12 |
Comments