Skip to content

Commit 5e3804e

Browse files
solves container with most water
1 parent 4edda66 commit 5e3804e

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
| 7 | [Reverse Integer](https://leetcode.com/problems/reverse-integer/) | [![Java](assets/java.png)](src/ReverseInteger.java) [![Python](assets/python.png)](python/reverse_integer.py) | [![java-yt](assets/java-yt.png)](https://youtu.be/7bOhyl5lWjI) [![python-yt](assets/python-yt.png)](https://youtu.be/lmLG30TLcSg) |
2020
| 8 | [String to Integer (atoi)](https://leetcode.com/problems/string-to-integer-atoi) | [![Java](assets/java.png)](src/StringToIntegerAtoi.java) | |
2121
| 9 | [PalindromeNumber](https://leetcode.com/problems/palindrome-number/) | [![Java](assets/java.png)](src/PalindromeNumber.java) [![Python](assets/python.png)](python/palindrome_number.py) | |
22+
| 11 | [Container With Most Water](https://leetcode.com/problems/container-with-most-water) | [![Java](assets/java.png)](src/ContainerWitMostWater.java) | |
2223
| 13 | [Roman To Integer](https://leetcode.com/problems/roman-to-integer/) | [![Java](assets/java.png)](src/RomanToInteger.java) [![Python](assets/python.png)](python/roman_to_integer.py) | [![java-yt](assets/java-yt.png)](https://youtu.be/BCue_mO_81A) [![python-yt](assets/python-yt.png)](https://youtu.be/8h_yGTNvKMA) |
2324
| 14 | [Longest Common Prefix](https://leetcode.com/problems/longest-common-prefix/) | [![Java](assets/java.png)](src/LongestCommonPrefix.java) [![Python](assets/python.png)](python/longest_common_prefix.py) | |
2425
| 20 | [ValidParentheses](https://leetcode.com/problems/valid-parentheses/) | [![Java](assets/java.png)](src/ValidParentheses.java) [![Python](assets/python.png)](python/valid_parentheses.py) | |

src/ContainerWitMostWater.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// https://leetcode.com/problems/container-with-most-water
2+
// T: O(n)
3+
// S: O(1)
4+
5+
public class ContainerWitMostWater {
6+
public static int maxArea(int[] height) {
7+
int water = 0;
8+
for (int i = 0, j = height.length - 1; i < j; ) {
9+
water = Math.max(water, Math.min(height[i], height[j]) * (j - i));
10+
if (height[i] > height[j]) j--;
11+
else i++;
12+
}
13+
return water;
14+
}
15+
}

0 commit comments

Comments
 (0)