81. Search in Rotated Sorted Array II

// Approach 1 Linear Search

 class Solution {

public:

    bool search(vector<int>& nums, int target) {

        

        for(int i=0;i<nums.size();i++){

            if(nums[i]==target)

                return true;

        }

};


Approach 2 Binary Search

First find pivot and select the portion where to move

Comments

Popular posts from this blog

1431. Kids With the Greatest Number of Candies

125. Valid Palindrome

771. Jewels and Stones