# A summary for rotated sorted array

• Find Minimum in Rotated Sorted Array
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/#/description

``````    public int findMin(int[] nums) {
int lo=0, hi=nums.length-1, mid=0;
while(lo<hi){
mid=lo+(hi-lo)/2;
if(nums[mid]>nums[hi]) lo=mid+1;
else hi=mid;
}
return nums[lo];
}
``````

Find Minimum in Rotated Sorted Array II
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii/#/description

``````    public int findMin(int[] nums) {
int lo=0, hi=nums.length-1, mid=0;
while(lo<hi){
mid=lo+(hi-lo)/2;
if(nums[mid]>nums[hi]) lo=mid+1;
else if(nums[mid]<nums[hi]) hi=mid;
else hi--;
}
return nums[lo];
}
``````

Search in Rotated Sorted Array
https://leetcode.com/problems/search-in-rotated-sorted-array/#/description

``````    public int search(int[] nums, int target) {
int lo=0, hi=nums.length-1, mid=0;
while(lo<=hi){
mid=lo+(hi-lo)/2;
if(nums[mid]==target) return mid;
else if(nums[mid]<nums[hi]){
if(target>nums[mid]&&target<=nums[hi]) lo=mid+1;
else hi=mid-1;
}else{
if(target<nums[mid]&&target>=nums[lo]) hi=mid-1;
else lo=mid+1;
}
}
return -1;
}
``````

Search in Rotated Sorted Array II
https://leetcode.com/problems/search-in-rotated-sorted-array-ii/#/description

``````    public boolean search(int[] nums, int target) {
int lo=0, hi=nums.length-1, mid=0;
while(lo<=hi){
mid=lo+(hi-lo)/2;
if(nums[mid]==target) return true;
else if(nums[mid]<nums[hi]){
if(target>nums[mid]&&target<=nums[hi]) lo=mid+1;
else hi=mid-1;
}else if(nums[mid]>nums[hi]){
if(target<nums[mid]&&target>=nums[lo]) hi=mid-1;
else lo=mid+1;
}else{
hi--;
}
}
return false;
}
``````

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