Easiest Python Solution | Beats 100% | 5 line solution
Intuition\n Describe your first thoughts on how to solve this problem. \nAlthough the problem wants us to partition the list nums into two lists and make it suc
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nAlthough the problem wants us to partition the list nums into two lists and make it such that the difference between the max of one list and the min of the other list is the least possible, we can simplify this problem by realizing all we need is the smallest difference between two values in the list. We could hypothetically partition the list there, although the problem just requires us to return this difference.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nThe easiest way to find where the smallest difference between two numbers is to sort the list and go through all adjacent values and keep track of the smallest difference.\n1. Create variable to keep track of the smallestDiff (currently max value)\n2. Sort the list (helps calculate the differences between all values)\n3. Iterate through the list (one less than length of nums)\n4. Check the difference between the next value and current value. If its less than the current smallest different, update our tracker for smallest difference\n\nNow, the problem wants us ideally to partition the lists and then calculate the highest value of the first list and the smallest value of the second list and find the difference of the two. But we\'ve already calculated the smallest difference. Our hypothetical partition, which we don\'t need to actually carry out, would be at the place of the smallest difference we calculated.\n \nInstead, we just return the smallest difference.\n\nOur time complexity if O(nlogn) because we sorted the list using the inbuilt sort algorithm from Python. Our space complexity is O(1) because we do not create any additional memory relative to input size growth.\n# Complexity\n- Time complexity:\n$$O(nlogn)$$\n- Space complexity:\n$$O(1)$$\n\n# Code\n```python3 []\nclass Solution:\n    def findValueOfPartition(self, nums: List[int]) -> int:\n        nums.sort()\n        minD = float(\'inf\')\n        for i in range(len(nums) - 1):\n            if nums[i+1] - nums[i] < minD:\n                minD = nums[i+1] - nums[i]\n        return minD\n```\n\n![Screenshot 2024-10-14 at 6.17.41\u202FPM.png](https://assets.leetcode.com/users/images/858a3463-5fb9-4f32-ad88-b084958b04b0_1728947879.8979623.png)\n
['Python3']