✅☑️ Easy C++ solution || Binary Search || Linear Search || Brute Force -> Optimize.
Intuition\n Describe your first thoughts on how to solve this problem. \nWe can Solved this question using Two approach.\n\n1. Using Linear Search (Brute Force)
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe can Solved this question using Two approach.\n\n1. Using Linear Search (Brute Force).\n2. Using Binary Search (Optimize).\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe can easily understand the All the approaches by seeing the code which is easy to understand with comments.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nTime complexity is given in code comment.\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nSpace complexity is given in code comment.\n\n# Code\n```\n/*\n\n    Time Complexity : O(N),  because we traversed over all the elements in the array, which has allowed us to\n    achieve a linear time complexity.\n\n    Space Complexity : O(1), the algorithm itself takes constant space but the program as a whole takes linear\n    space because of storing the input array.\n\n    Using Array + Linear Search. \n\n*/\n\n\n/***************************************** Approach 1 First Code *****************************************/\n\nclass Solution {\npublic:\n    int findMin(vector<int>& nums) {\n        int n = nums.size();\n        int minimum = nums[0];\n        for(int i=1; i<n; i++){\n            minimum = min(nums[i], minimum);\n        }\n        return minimum;\n    }\n};\n\n\n\n\n\n\n/***************************************** Approach 1 Second Code *****************************************/\n\nclass Solution {\npublic:\n    int findMin(vector<int>& nums) {\n        int n = nums.size();\n        for(int i=0; i<n-1; i++){\n            if(nums[i] > nums[i+1]){\n                return nums[i+1];\n            }\n        }\n        return nums[0];\n    }\n};\n\n\n\n\n\n\n/*\n\n    Time Complexity : O(log N) where N is the number of elements in the input array. Here we used binary search\n    which takes logarithmic time complexity. All of this possible because the array was initially sorted.\n\n    Space Complexity : O(1), this approach takes also constant time but the program as a whole takes O(N) space\n    because of the space required to store the input.\n\n    Using Array + Binary Search.\n\n*/\n\n\n/***************************************** Approach 2 First Code *****************************************/\n\nclass Solution {\npublic:\n    int findMin(vector<int>& nums) {\n        int low = 0;\n        int high = nums.size()-1;\n        while(low < high){\n            int mid = low + (high-low)/2;\n            if(nums[mid] < nums[high]){\n                high = mid;\n            }\n            else{\n                low = mid+1;\n            }\n        }\n        return nums[low];\n    }\n};\n```
['Array', 'Binary Search', 'C++']