728x90
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | public int solution(int[] H) { // write your code in Java SE 8 Stack<Integer> st = new Stack<>(); int answer = 0; for(int h : H){ while(!st.isEmpty() && st.peek()>h){ st.pop(); } if(st.isEmpty() || st.peek()<h){ st.push(h); answer++; } } return answer; } | cs |
'알고리즘 풀이 > Codility' 카테고리의 다른 글
Codility - Dominator (Leader) (0) | 2019.12.13 |
---|---|
Codility - Nesting (Stacks and Queues) (0) | 2019.12.13 |
Codility - Fish (Stacks and Queues) (0) | 2019.12.13 |
Codility - Brackets (Stacks and Queues) (0) | 2019.12.13 |
Codility - Triangle (Sorting) (0) | 2019.12.13 |