Skip to content

feat: add ts solution to lc problem: No.0704 #3193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jul 3, 2024
Prev Previous commit
Update Solution.cs
  • Loading branch information
yanglbme authored Jul 3, 2024
commit 5435b584c20d77121e3ff7b0353e4d33266ee538
14 changes: 7 additions & 7 deletions solution/0700-0799/0704.Binary Search/Solution.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
public class Solution {
public int Search(int[] nums, int target) {
int left = 0, right = nums.Length - 1;
while (left < right) {
int mid = (left + right) >> 1;
int l = 0, r = nums.Length - 1;
while (l < r) {
int mid = (l + r) >> 1;
if (nums[mid] >= target) {
right = mid;
r = mid;
} else {
left = mid + 1;
l = mid + 1;
}
}
return nums[left] == target ? left : -1;
return nums[l] == target ? l : -1;
}
}
}
Loading