import java.util.*;
class Solution {
public int solution(int[] H) {
int count = 0;
Stack<Integer> stack = new Stack<>();
for (int h : H) {
while (!stack.empty() && stack.peek() > h) {
stack.pop();
}
if (stack.empty() || stack.peek() != h) {
count++;
}
stack.push(h);
}
return count;
}
}
Codility - StoneWall
2018년 3월 6일 화요일
·