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;              }
点赞 评论

相关推荐

牛客83700679...:简历抄别人的,然后再投,有反馈就是简历不行,没反馈就是学历不行,多投多改只要技术不差机会总会有的
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务