“Mountain Array LeetCode” Respostas de código

Mountain Array LeetCode

class Solution:
    def peakIndexInMountainArray(self, arr: List[int]) -> int:
        start = 0
        end = len(arr)-1
        
        while (start < end):
            mid = start + (end-start)//2
            if (arr[mid]>arr[mid+1]):
                end = mid
            else: start = mid+1
        return start
Prabhu Kiran Konda

Mountain Array LeetCode

class Solution {    
    public static int peakIndexInMountainArray(int[] arr) {
        int start = 0;
        int end = arr.length-1;

        while(start < end){
            int mid = start + (end-start)/2;

            if (arr[mid] > arr[mid+1]) end = mid;
            else start = mid+1;
        }
        return start;
    }
}
Prabhu Kiran Konda

Respostas semelhantes a “Mountain Array LeetCode”

Perguntas semelhantes a “Mountain Array LeetCode”

Mais respostas relacionadas para “Mountain Array LeetCode” em Java

Procure respostas de código populares por idioma

Procurar outros idiomas de código