Skip to content

Commit 485cb35

Browse files
committed
added function
1 parent 0fe71e6 commit 485cb35

File tree

1 file changed

+6
-1
lines changed
  • Find First and Last Position of Element in Sorted Array

1 file changed

+6
-1
lines changed

Find First and Last Position of Element in Sorted Array/code.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ var searchRange = function(nums, target) {
2121
// reset low and high
2222
low = 0, high = nums.length-1;
2323

24-
24+
// find the end
25+
while(low <= high) {
26+
mid = Math.floor((low+high)/2);
27+
if(nums[mid] <= target) low = mid+1;
28+
else high = mid-1;
29+
}
2530
return [start, high];
2631
};

0 commit comments

Comments
 (0)