首页 > 代码库 > Container With Most Water
Container With Most Water
-----QUESTION-----
Given
Note: You may not slant the container.
-----SOLUTION-----
class Solution { public: int maxArea(vector<int> &height) { if(height.size() ==1) return 0; int width; int tall; result = 0; int i = 0; int j = height.size()-1; while(i<j) { tall = min(height[i],height[j]); width = j-i; if(tall*width > result) result = tall*width; if(height[i] > height[j]) j--; else i++; } return result; } private: int result; };以下算法在judge large时time limit exceeded
class Solution { public: int maxArea(vector<int> &height) { if(height.size() ==1) return 0; int width; int tall; result = 0; for(int i = 1; i< height.size(); i++) { for(int j = i+1; j<height.size(); j++) { tall = min(height[i],height[j]); width = j-i; if(tall*width > result) result = tall*width; } } return result; } private: int result; };
Container With Most Water
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。