0035. 搜索插入位置 #14
utterances-bot
started this conversation in
Comments
Replies: 3 comments
-
第6行ans=n没必要吧 |
Beta Was this translation helpful? Give feedback.
0 replies
-
感谢指正,已删除~~ |
Beta Was this translation helpful? Give feedback.
0 replies
-
c++ class Solution {
public:
int searchInsert(vector<int>& nums, int target) {
int n = nums.size();
int left = 0, right = n - 1;
while (left <= right) {
int mid = left + ((right - left) / 2);
if (nums[mid] < target) {
left = mid + 1;
} else {
right = mid - 1;
}
}
return left;
}
}; |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
0035. 搜索插入位置 | 算法通关手册
https://algo.itcharge.cn/Solutions/0001-0099/search-insert-position
Beta Was this translation helpful? Give feedback.
All reactions