This is the similiar problem with: https://www.cnblogs.com/feiflytech/p/16168587.html and https://www.cnblogs.com/feiflytech/p/16169025.html

class Solution {
    public int[] canSeePersonsCount(int[] heights) {
        int[] res = new int[heights.length];
        Stack<Integer> stk = new Stack<>();
        for(int i=0;i<heights.length;i++){
            while(!stk.isEmpty()&& heights[i]>=heights[stk.peek()]){
                res[stk.pop()]++;
            }
            if(!stk.isEmpty())
                res[stk.peek()]++;
            stk.push(i);
        }
        return res;
    }
}

 

posted on 2022-04-20 11:59  阳光明媚的菲越  阅读(11)  评论(0编辑  收藏  举报