Find Minimum in Rotated Sorted Array - Java Solution (Beats 100%)
Intuition\n Describe your first thoughts on how to solve this problem. \nAs the given array (with unique elements) is rotated k (unknown) times and it\'s sorted
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nAs the given array (with **unique** elements) is rotated k (unknown) times and it\'s sorted in non-decreasing order, which means there must exist a single element where it becomes the greater than the last element of Array. Taking this observation into consideration, I employed binary search to ascertain the minimum element. \n# Approach\n<!-- Describe your approach to solving the problem. -->\nMy approach adeptly utilizes binary search to identify the rotation point in a rotated sorted array with unique elements. By recognizing the crucial point where an element surpasses the last one, my algorithm efficiently adjusts the search range to pinpoint the minimum element, ensuring a time complexity of O(log n).\nThe steps incorporated in my approach are as follows :\n\n- "start" is initialized to the beginning of the array (0).\n"end" is initialized to the end of the array (nums.length - 1).\n\n- The while loop continues to run until the "start" index is less than or equal to the "end" index. Within the loop, the middle index is calculated, and subsequently, a check for the minimum element is performed.\n\n- We check if mid is greater than 0 and if nums[mid] is less than nums[mid - 1]. If this condition is true, it means we\'ve found the minimum element, and return nums[mid].\n- If the above condition is not true, then we updates the search range at last and continues the searching. \n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n**The time complexity is O(log n)**, where "n" is the length of the input array. This is because the binary search approach efficiently reduces the search space in each iteration.\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n**The space complexity is O(1)** since the algorithm uses a constant amount of extra space for variables like "start," "end," and "mid," regardless of the size of the input array.\n# Code\n```\nclass Solution {\n    public int findMin(int[] nums) {\n        int start = 0;\n        int end = nums.length - 1;\n\n        while (start <= end) {\n            int mid = start + (end - start) / 2;\n\n            if (mid > 0 && nums[mid] < nums[mid - 1]) {\n                return nums[mid];\n            } else if (nums[mid] > nums[end]) {\n                start = mid + 1;\n            } else {\n                end = mid - 1;\n            }\n        }\n        return nums[start];\n    }\n}\n\n```
['Java']