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

相关推荐

2025-12-29 22:34
武汉大学 Java
点赞 评论 收藏
分享
点赞 评论 收藏
分享
程序员花海:实习和校招简历正确格式应该是教育背景+实习+项目经历+个人评价 其中项目经历注意要体现业务 实习经历里面的业务更是要自圆其说 简历模板尽可能保持干净整洁 不要太花哨的
秋招吐槽大会
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务