Skip to content

Conversation

@jhm9595
Copy link
Owner

@jhm9595 jhm9595 commented Dec 5, 2022

Time Complexity : O(logN)

@jhm9595 jhm9595 requested a review from bigelephant29 December 5, 2022 06:46
int l = 0;
int r = nums.length - 1;

int midIdx = (l + r) / 2;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not pretty sure why you put this outside.

I think you can directly calculate midIdx in each iteration in the while loop.

}else {
break;
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see in the first half of your code, you're trying to binary search on the position of your target, but I'm not sure why the latter part is trying to brute force all the positions.

Theoretically you should be able to find both points with binary search.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants