Easy Beats 100% || CPP || 0 ms
Intuition\nTricky one. Do refer Hint before seeing solution. Try dry running for small vectors, eventually you will be able to build logic.\n# Approach\nWe know
# Intuition\nTricky one. Do refer Hint before seeing solution. Try dry running for small vectors, eventually you will be able to build logic.\n# Approach\nWe know if(nums[0]>nums[nums.size()-1]) , we got rotated array. if there are 3 elements a,b,c in ascending fashion, we know a<b<c.\nBut Now we will get a point where either a>b or b>c. Then return smallest, thats our answer.\nI compared mid with nums[0] and nums[n] to figure out which side smallest would lie. Try dry running with yourself.\n\n# Complexity\n- Time complexity:\nO(logN)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\npublic:\n     int findMin(vector<int>& nums) {\n        if(nums.size()==1) return nums[0];\n\n        if(nums[0]<nums[nums.size()-1]) return nums[0];\n\n        int a=0;\n        int b=nums.size()-1;\n\n        while(a<b){\n            int mid=(a+b)/2;\n\n            if(b-a==1){\n                if(nums[b]<nums[a]) return nums[b]; \n            }\n\n            if(nums[mid-1]>nums[mid]) return nums[mid];\n\n            else if(nums[mid]>nums[mid+1]) return nums[mid+1];\n\n            if(nums[mid]>nums[0]) a=mid+1;\n\n            else \n            b=mid-1;\n\n        }\n        return 0;\n    }\n};\n```\nPlease Upvote if u liked my explanation.\n![upvote.jpeg](https://assets.leetcode.com/users/images/6d938979-1223-4f6d-833f-2e10aa564133_1706607940.7488573.jpeg)\n\n\n
['C++']