Search rotated array

Descrição

FlashCards sobre Search rotated array, criado por Suhas S em 12-02-2018.
Suhas S
FlashCards por Suhas S, atualizado more than 1 year ago
Suhas S
Criado por Suhas S mais de 7 anos atrás
3
0
1 2 3 4 5 (0)

Resumo de Recurso

Questão Responda
Search rotated array class Solution { public int search(int[] nums, int target) { int low = 0, high = nums.length - 1; int x = target; while(low <= high){ int mid = (low+high)/2 ; if(nums[mid] == x ) return mid; if( nums[mid] <= nums[high]){ if(x > nums[mid] && x <= nums[high]){ low = mid + 1; }else high = mid - 1; }else if(nums[mid] >= nums[low]){ if(x >= nums[low] && x < nums[mid] ){ high = mid - 1; }else low = mid + 1; } } return -1; } }

0 comentários

There are no comments, be the first and leave one below:

Semelhante

JavaScript Fundamentals
Andrew Watters
Two-Dimensional Arrays
José Miguel Gallardo
Arrays - Vocabulary
vgeetha
Arrays
Tony Meman
Arrays
vgeetha
Data Types - Arrays and Records
Adele Tidball
Arrays
Jenny Degling
Computer science unit 2
tabassum88 abedi
Computer science unit 2
tabassum88 abedi