Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 58ed016

Browse files
authored
Merge pull request #19 from thuanle123/main
Added 11 Container With Most Water and 55 Jump Game Java
2 parents 1fd22ac + d3e2790 commit 58ed016

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public int maxArea(int[] height) {
3+
int left = 0;
4+
int right = height.length - 1;
5+
int res = 0;
6+
while (left < right) {
7+
int containerLength = right - left;
8+
int area = containerLength * Math.min(height[left], height[right]);
9+
res = Math.max(res, area);
10+
if (height[left] < height[right]) {
11+
left++;
12+
} else {
13+
right--;
14+
}
15+
}
16+
return res;
17+
}
18+
}

java/55-Jump-Game.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public boolean canJump(int[] nums) {
3+
int goal = nums.length-1;
4+
for (int i = nums.length-2; i >= 0; i--) {
5+
if (nums[i] + i >= goal) {
6+
goal = i;
7+
}
8+
}
9+
return goal == 0;
10+
}
11+
}
12+

0 commit comments

Comments
 (0)