class Solution { public: string longestPalindrome(string s) { int length = s.length(); ) return s; ; ; int **pS = new int *[length];//palindromic state ;i < length; i++) pS[i] = ]; ; i < length;i++) { pS[i][] = ; pS[i][] = ; } ; i <= length; i++)…
class Solution { public: int maxArea(vector<int>& height) { ; ; ; while(l < r) { int h = min(height[l], height[r]); int area = h * (r-l); if (area > max) max = area; while (height[l] <= h && l < r) l++; while (height[r] <=…
我现在在做一个叫<leetbook>的免费开源书项目,力求提供最易懂的中文思路,目前把解题思路都同步更新到gitbook上了,需要的同学可以去看看 书的地址:https://hk029.gitbooks.io/leetbook/ 011. Container With Most Water[M] 问题 Given n non-negative integers a1, a2, …, an, where each represents a point at coordinate (i, ai).…
Description Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis for…
1.题目描述 2.题目分析 首先,这个题可以使用暴力解法,时间复杂度是O(n^2),这个显然是最容易的做法,但是效率不够高,题目提供了一种解法,使用两个指针,一个从头向尾部,另外一个从尾部向头部,每一步寻找最大的面积,然后较小的一边向前移动. 3.代码实现 int maxArea(vector<int>& height) { ; ; pb < pe ; ) { max_area = max( max_area ,min(*pb , *pe)*(int)(pe -pb)); if(…
题目:Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a conta…
Problem: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a…
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a containe…
题目 Given n non-negative integers a1, a2, -, an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a contain…
题目如下: 题目的意思是求容器能装的最大的水量,当时我按梯形的面积来算,一直不对,后来才发现要按矩形的面积来算 Python代码如下: def maxArea(self, height): """ :type height: List[int] :rtype: int """ right = len(height)-1 left = 0 maxWater = 0 while(left<right): maxWater = max(maxWa…