Skip to content

Commit

Permalink
longest palindrome substring
Browse files Browse the repository at this point in the history
  • Loading branch information
Sherali Obidov committed Jun 28, 2018
1 parent 1414b75 commit 0c66245
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/problems/Medium.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2740,4 +2740,10 @@ Note: "aba" is also a valid answer.
Example 2:

Input: "cbbd"
Output: "bb"
Output: "bb"

187)Container With Most Water
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 container, such that the container contains the most water.

Note: You may not slant the container and n is at least 2.

24 changes: 24 additions & 0 deletions src/problems/medium/ContainerWithMostWater.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package problems.medium;

/**
* Why Did you create this class? what does it do?
*/
public class ContainerWithMostWater {
public int maxArea(int[] a) {
if (a == null || a.length == 0) {
return 0;
}
int max = 0;
int l = 0;
int r = a.length - 1;
while (l < r) {
max = Math.max(max, Math.min(a[r], a[l]) * (r - l));
if (a[r] > a[l]) {
l++;
} else {
r--;
}
}
return max;
}
}

0 comments on commit 0c66245

Please sign in to comment.