Skip to content

Commit

Permalink
Time: 70 ms (79.42%), Space: 50.9 MB (85.19%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
Reechychukz committed Jul 25, 2023
1 parent 473ce3f commit b4df92f
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@
* @return {number}
*/
var peakIndexInMountainArray = function(arr) {
//if (arr[0] <= arr[])
for (let i = 0; i < arr.length - 1; i++) {
if (arr[i] > arr[i + 1]) return i;
let l = 0,
mid,
r = arr.length - 1;

while (l < r) {
mid = Math.floor((l + r) / 2);

if (arr[mid] < arr[mid + 1]) l = mid + 1;
else r = mid;
}
return l;
};

0 comments on commit b4df92f

Please sign in to comment.