Files
leetcode/35.search-insert-position.java
2025-05-17 17:06:34 +08:00

25 lines
508 B
Java

/*
* @lc app=leetcode id=35 lang=java
*
* [35] Search Insert Position
*/
// @lc code=start
class Solution {
public int searchInsert(int[] nums, int target) {
int l=0, r = nums.length;
int m;
while(l<r) {
m = l + (r-l)/2;
if(nums[m] >= target) {
r = m;
} else {
l = m + 1;
}
}
return l;
}
}
// @lc code=end