Skip to content

Commit 81ee05e

Browse files
author
rchen102
committed
review 3
1 parent e12335d commit 81ee05e

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

Java/leetcode 1.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ public int[] twoSum(int[] nums, int target) {
55
if (nums == null || nums.length == 0) return res;
66
Map<Integer, Integer> map = new HashMap<>();
77
for (int i = 0; i < nums.length; i++) {
8-
if (map.containsKey(target-nums[i])) {
9-
res[0] = i;
10-
res[1] = map.get(target-nums[i]);
8+
int wanted = target - nums[i];
9+
if (map.containsKey(wanted)) {
10+
res[0] = map.get(wanted);
11+
res[1] = i;
1112
return res;
1213
}
13-
map.put(nums[i], i);
14+
else {
15+
map.put(nums[i], i);
16+
}
1417
}
1518
return res;
1619
}

Java/leetcode 11.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
class Solution {
66
public int maxArea(int[] height) {
77
int res = 0;
8-
if (height == null || height.length == 0) return res;
98
int left = 0, right = height.length - 1;
109
while (left < right) {
11-
int area = Math.min(height[left], height[right]) * (right - left);
12-
res = Math.max(res, area);
10+
int row = right - left;
11+
int tall = Math.min(height[left], height[right]);
12+
res = Math.max(res, row * tall);
1313
if (height[left] < height[right]) left++;
1414
else if (height[left] > height[right]) right--;
1515
else {

0 commit comments

Comments
 (0)