Search for a Range
same idea. But I use 2 helpers to find the left and right boundaries.
@lhai it a bit operation for the division. Bit operation is faster than regular arithmetic operation
My naive approach.
concise and simple!
@caikehe great job! much tight and clean than mine
Here is my solution, I used a bit slower way but it works.
Step1. Binary search for the target
Step2. Search towards left and right
Both the search routines can be combined into one. Below is implementation for recursive approach.
@leetchunhui Actually, if end = nums.size()-1, it doesn't work.
you ignore the possibility of the input 
should rewrite as
I think your code will fail on test case [1,2] given target is 0.
Sure and I think I did it, my code is here
No one has replied
the compare function is anonymous function, this is new feature in C++11, you can see the article about it following this link http://en.wikipedia.org/wiki/C%2B%2B11
@fakenda the running time is not O(logn)
Thanks for sharing. I have the same idea target-0.5/target+0.5, but the code is little different. The left and right boundary are enough for checking.
PS: I have tested this code for 3 times, the second test used 8 ms while other two used 4 ms.
Disabled Categories are greyed out
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.