public int solution(int[] heights) {         int n = heights.length;         if(n==0) return 0;         int[] left = new int[n];         int[] right = new int[n];         int res = 0;         Stack<Integer> s = new Stack<Integer>();         for(int i = 0 ;i<n;i++){             for(;!s.isEmpty()&&heights[i]<=heights[s.peek()];s.pop());             left[i] = s.isEmpty()?0:s.peek()+1;             s.push(i);         }         s.clear();         for(int i = n-1;i>=0;i--){             for(;!s.isEmpty()&&heights[i]<=heights[s.peek()];s.pop());             right[i] = s.isEmpty()?n-1:s.peek()-1;             s.push(i);         }         for(int i = 0;i<n;i++){             res = Math.max(res,(right[i]-left[i]+1)*heights[i]);         }         return res;              }
点赞 评论

相关推荐

工科女的日常:真诚建议:别再用这种花哨的模板,可以看看我发的那个零经验找实习发帖子
点赞 评论 收藏
分享
04-15 23:42
中山大学 Java
ResourceUtilization:过几天楼主就会捧着一堆offer来问牛友们该怎么选辣
点赞 评论 收藏
分享
牛客网
牛客企业服务