Most optimal solution using binary search | C++ and JAVA code
\n\n# Approach\nIdentify the sorted half from the array, pickup the smallest element from that half, update the answer if it is smaller than the answer, then el
\n\n# Approach\nIdentify the sorted half from the array, pickup the smallest element from that half, update the answer if it is smaller than the answer, then eliminate that half. Repeat this until the search space gets exhausted.\n\n# Complexity\n- Time complexity:\nO(log(n))\n\n- Space complexity:\nO(1)\n\n# C++ Code\n```\nclass Solution {\npublic:\n    int findMin(vector<int>& nums) {\n        int low = 0, high = nums.size()-1, ans = INT_MAX;\n        while(low<=high) {\n            int mid = (low+high)/2;\n            if(nums[low]<=nums[mid]) {\n                ans = min(ans, nums[low]);\n                low = mid+1;\n            } else {\n                ans = min(ans, nums[mid]);\n                high = mid-1;\n            }\n        }\n        return ans;\n    }\n};\n```\n# JAVA Code\n```\npublic class Solution {\n    public int findMin(int[] nums) {\n        int low = 0, high = nums.length - 1, ans = Integer.MAX_VALUE;\n        while (low <= high) {\n            int mid = (low + high) / 2;\n            if (nums[low] <= nums[mid]) {\n                ans = Math.min(ans, nums[low]);\n                low = mid + 1;\n            } else {\n                ans = Math.min(ans, nums[mid]);\n                high = mid - 1;\n            }\n        }\n        return ans;\n    }\n}\n```\n
['Array', 'Binary Search', 'C++', 'Java']