My passed C# solution


  • 0
    Y
    public int FindPeakElement(int[] nums) {
           if (nums.Length < 2)
                return 0;
            int start = 0;
            int end = nums.Length - 1;
            while (start < end - 1)
            {
                int mid = (start + end) / 2;
                if (nums[mid] > nums[mid + 1])
                {
                    end = mid;
                }
                else
                {
                    start = mid + 1;
                }
            }
    
            return nums[start] > nums[end] ? start : end;
    }

Log in to reply
 

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