GoConqr has a new look! Let us know what you think.

Flashcards

Search rotated array

Suhas S English 1 card

Cards in this deck (1)

  1. 1Search rotated arrayclass 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;
    }
    }

Information

Description
Flashcards on Search rotated array, created by Suhas S on 12/02/2018.
Created by
Suhas S
Views
11
Tags
arrays
Rating

Feedback

What is it about?

What do you think of the new look?

How do you like it?