Search rotated array

Description

Flashcards on Search rotated array, created by Suhas S on 12/02/2018.
Suhas S
Flashcards by Suhas S, updated more than 1 year ago
Suhas S
Created by Suhas S over 7 years ago
1
0
1 2 3 4 5 (0)

Resource summary

Question Answer
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; } }
Show full summary Hide full summary

0 comments

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

Similar

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