Skip to content

Commit 665141b

Browse files
authored
Update Search Insert Position.java
1 parent 80d54ce commit 665141b

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

Easy/Search Insert Position.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
class Solution {
22
public int searchInsert(int[] nums, int target) {
3-
int low = 0;
4-
int high = nums.length - 1;
5-
while (low <= high) {
6-
int mid = (low + high) / 2;
3+
int left = 0;
4+
int right = nums.length - 1;
5+
while (left <= right) {
6+
int mid = (left + right) / 2;
77
if (nums[mid] == target) {
88
return mid;
9-
}
10-
else if (nums[mid] > target) {
11-
high = mid - 1;
12-
}
13-
else {
14-
low = mid + 1;
9+
} else if (nums[mid] > target) {
10+
right = mid - 1;
11+
} else {
12+
left = mid + 1;
1513
}
1614
}
17-
return low;
15+
return left;
1816
}
1917
}

0 commit comments

Comments
 (0)