Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[pull] master from youngyangyang04:master #105

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
pull merged 7 commits into AlgorithmAndLeetCode:master from youngyangyang04:master
Oct 6, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update 0035.搜索插入位置.md
增加C语言两种版本,通过Leetcode测试
  • Loading branch information
vanyongqi authored Sep 30, 2022
commit 4276745f1ba4b048c022013edddb89d3959fd49b
6 changes: 3 additions & 3 deletions problems/0035.搜索插入位置.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -440,10 +440,10 @@ int searchInsert(int* nums, int numsSize, int target){
while(left <= right){//左闭右闭区间 所以可以 left == right
mid = left + (right - left) / 2;
if(target < nums[mid]){
//target 在左区间 [left, middle - 1]中,原区间包含mid,右区间边界可以向左内缩
//target 在左区间 [left, mid - 1]中,原区间包含mid,右区间边界可以向左内缩
right = mid -1;
}else if( target > nums[mid]){
//target 在右区间 [mid + 1, right]中,原区间包含mid,左区间边界可以向右内缩
//target 在右区间 [mid + 1, right]中,原区间包含mid,左区间边界可以向右内缩
left = mid + 1;
}else {
// nums[mid] == target ,顺利找到target,直接返回mid
Expand All @@ -465,7 +465,7 @@ int searchInsert(int* nums, int numsSize, int target){
while(left < right){//左闭右闭区间 所以 left < right
mid = left + (right - left) / 2;
if(target < nums[mid]){
//target 在左区间 [left, mid)中,原区间没有包含mid,右区间边界可以不能内缩
//target 在左区间 [left, mid)中,原区间没有包含mid,右区间边界不能内缩
right = mid ;
}else if( target > nums[mid]){
// target 在右区间 [mid+1, right)中,原区间包含mid,左区间边界可以向右内缩
Expand Down

AltStyle によって変換されたページ (->オリジナル) /