✅Find Minimum in Rotated Sorted Array || W/ Approach || C++ | JAVA | Python
Idea\n\n We basically need to find the smallest element\nWe can do that by binary search as follows:\n Binary search, left (Starting) = 0, right (Last element) 
**Idea**\n\n* We basically need to find the smallest element\nWe can do that by binary search as follows:\n* Binary search, left (Starting) = 0, right (Last element) = n-1\n* `mid = left + (right - left) / 2 // Or (Left + Right)/2` \n* If `nums[left] > nums[right]`, then `nums[left]` is the minimum (Basically, after completing the iteration or on not fullfillment of the condition, we will reach here. Else we continue traversing)\n* Else, traverse\n\t* If `nums[mid] > nums[right]` then search on the right side, because smaller elements are in the right side\n\t* Else search on the left side.\n\n**SOLUTION**\n`In C++`\n```\nclass Solution {\npublic:\n    int findMin(vector<int>& nums) {\n        int left = 0 , right = nums.size()-1 ;\n        if (!right)  // Case of single element\n            return nums[0] ;\n        while (left < right)\n        {\n            int mid = left + (right - left) / 2;\n            if (nums[left] < nums[right]) \n                return nums[left];  // Smaller element\n            else if (nums[mid] > nums[right]) \n                left = mid + 1;  // Check on right\n            else \n                right = mid; // Check on left\n        }\n        return nums[left];\n    }\n};\n```\n`In JAVA`\n```\nclass Solution {\n    public int findMin(int[] nums) {\n        int left = 0;\n        int right = nums.length - 1;\n        \n        while(left < right){\n            int mid = left + (right - left) /2;\n            \n            if(nums[mid] > nums[right])\n            {\n                left = mid + 1;\n            }\n            else if(nums[mid] < nums[right])\n            {\n                right = mid;\n            }\n            else\n            {\n                return nums[right];\n            }\n        }\n        return nums[left];\n    }\n}\n```\n`In Python`\n```\nclass Solution(object):\n    def findMin(self, nums):\n        """\n        :type nums: List[int]\n        :rtype: int\n        """\n        left, right = 0, len(nums)-1\n        while left < right:\n            mid = (left + right) // 2\n            if nums[mid] > nums[right]:\n                left = mid + 1\n            else:\n                right = mid\n        return nums[left]\n```\n**TIME COMPLEXITY - O(logN)**\nIf you want to try a harder problem of a similar type, try out [33. Search in Rotated Sorted Array](https://leetcode.com/problems/search-in-rotated-sorted-array/).
[]