C# - binary technique, same as others but only beats 40%, why is that?


  • 0

    This solution is from what I can tell the same as many others. Why is it performing worse? Any thoughts? Thank You!

    public int FindPeakElement(int[] nums) {
        int left = 0;
        int right = nums.Length - 1;
        while (left < right)
        {
            int mid = (left + right)/2;
            int midNext = mid + 1;
            
            if (nums[mid] < nums[midNext])
            {
                left = midNext;
            }
            else
            {
                right = mid;
            }
        }
        return left;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.