Best O(LogN) Solution
Approach 1\nSorting\n\n# Complexity\n- Time complexity:\nO(nlogn)\n\n- Space complexity:\nO(1) \n\n# Code\n\nclass Solution {\npublic:\n    int findMin(vector<i
# Approach 1\nSorting\n\n# Complexity\n- Time complexity:\n$$O(nlogn)$$\n\n- Space complexity:\n$$O(1)$$ \n\n# Code\n```\nclass Solution {\npublic:\n    int findMin(vector<int>& nums) {\n        sort (nums.begin(), nums.end());\n        return nums[0];\n    }\n};\n```\n# Approach 2\nLinear Search\n\n# Complexity\n- Time complexity:\n$$O(n)$$\n\n- Space complexity:\n$$O(1)$$ \n\n# Code\n```\nclass Solution {\npublic:\n    int findMin(vector<int>& nums) {\n        int minVal = nums[0];\n        for (int i = 1; i < nums.size(); i++)\n            minVal = min (nums[i], minVal);\n        return minVal;\n    }\n};\n```\n\n# Approach 3\nBinary Search\n\n# Complexity\n- Time complexity:\n$$O(logn)$$\n\n- Space complexity:\n$$O(1)$$ \n\n# Code\n```\nclass Solution {\npublic:\n    int findMin(vector<int>& nums) {\n        int n = nums.size();\n        if (n == 1)\n            return nums[0];\n        if (nums[0] < nums[n - 1])\n            return nums[0];\n        int low = 0, high = n - 1;\n        while (low <= high) {\n            int mid = (low + high) / 2;\n            if (nums[mid] > nums[mid + 1])\n                return nums[mid + 1];\n            if (nums[mid] < nums[mid - 1])\n                return nums[mid];   \n            if (nums[low] < nums[mid])\n                low = mid + 1;\n            else if (nums[high] > nums[mid])\n                high = mid - 1;\n        }\n        return -1;\n    }\n};\n```
['C++']