Class Solution
java.lang.Object
g2701_2800.s2740_find_the_value_of_the_partition.Solution
2740 - Find the Value of the Partition.<p>Medium</p>
<p>You are given a <strong>positive</strong> integer array <code>nums</code>.</p>
<p>Partition <code>nums</code> into two arrays, <code>nums1</code> and <code>nums2</code>, such that:</p>
<ul>
<li>Each element of the array <code>nums</code> belongs to either the array <code>nums1</code> or the array <code>nums2</code>.</li>
<li>Both arrays are <strong>non-empty</strong>.</li>
<li>The value of the partition is <strong>minimized</strong>.</li>
</ul>
<p>The value of the partition is <code>|max(nums1) - min(nums2)|</code>.</p>
<p>Here, <code>max(nums1)</code> denotes the maximum element of the array <code>nums1</code>, and <code>min(nums2)</code> denotes the minimum element of the array <code>nums2</code>.</p>
<p>Return <em>the integer denoting the value of such partition</em>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums = [1,3,2,4]</p>
<p><strong>Output:</strong> 1</p>
<p><strong>Explanation:</strong> We can partition the array nums into nums1 = [1,2] and nums2 = [3,4].</p>
<ul>
<li>The maximum element of the array nums1 is equal to 2.</li>
<li>The minimum element of the array nums2 is equal to 3.</li>
</ul>
<p>The value of the partition is |2 - 3| = 1.</p>
<p>It can be proven that 1 is the minimum value out of all partitions.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums = [100,1,10]</p>
<p><strong>Output:</strong> 9</p>
<p><strong>Explanation:</strong> We can partition the array nums into nums1 = [10] and nums2 = [100,1].</p>
<ul>
<li>The maximum element of the array nums1 is equal to 10.</li>
<li>The minimum element of the array nums2 is equal to 1.</li>
</ul>
<p>The value of the partition is |10 - 1| = 9.</p>
<p>It can be proven that 9 is the minimum value out of all partitions.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>2 <= nums.length <= 10<sup>5</sup></code></li>
<li><code>1 <= nums[i] <= 10<sup>9</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
findValueOfPartition
public int findValueOfPartition(int[] nums)
-