mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-04 23:11:41 +08:00
update
This commit is contained in:
48
leetcode/problem/find-the-value-of-the-partition.html
Normal file
48
leetcode/problem/find-the-value-of-the-partition.html
Normal file
@@ -0,0 +1,48 @@
|
||||
<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> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,3,2,4]
|
||||
<strong>Output:</strong> 1
|
||||
<strong>Explanation:</strong> We can partition the array nums into nums1 = [1,2] and nums2 = [3,4].
|
||||
- The maximum element of the array nums1 is equal to 2.
|
||||
- The minimum element of the array nums2 is equal to 3.
|
||||
The value of the partition is |2 - 3| = 1.
|
||||
It can be proven that 1 is the minimum value out of all partitions.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [100,1,10]
|
||||
<strong>Output:</strong> 9
|
||||
<strong>Explanation:</strong> We can partition the array nums into nums1 = [10] and nums2 = [100,1].
|
||||
- The maximum element of the array nums1 is equal to 10.
|
||||
- The minimum element of the array nums2 is equal to 1.
|
||||
The value of the partition is |10 - 1| = 9.
|
||||
It can be proven that 9 is the minimum value out of all partitions.
|
||||
</pre>
|
||||
|
||||
<p> </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>
|
35
leetcode/problem/painting-the-walls.html
Normal file
35
leetcode/problem/painting-the-walls.html
Normal file
@@ -0,0 +1,35 @@
|
||||
<p>You are given two <strong>0-indexed</strong> integer arrays, <code>cost</code> and <code>time</code>, of size <code>n</code> representing the costs and the time taken to paint <code>n</code> different walls respectively. There are two painters available:</p>
|
||||
|
||||
<ul>
|
||||
<li>A<strong> paid painter</strong> that paints the <code>i<sup>th</sup></code> wall in <code>time[i]</code> units of time and takes <code>cost[i]</code> units of money.</li>
|
||||
<li>A<strong> free painter</strong> that paints <strong>any</strong> wall in <code>1</code> unit of time at a cost of <code>0</code>. But the free painter can only be used if the paid painter is already <strong>occupied</strong>.</li>
|
||||
</ul>
|
||||
|
||||
<p>Return <em>the minimum amount of money required to paint the </em><code>n</code><em> walls.</em></p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> cost = [1,2,3,2], time = [1,2,3,2]
|
||||
<strong>Output:</strong> 3
|
||||
<strong>Explanation:</strong> The walls at index 0 and 1 will be painted by the paid painter, and it will take 3 units of time; meanwhile, the free painter will paint the walls at index 2 and 3, free of cost in 2 units of time. Thus, the total cost is 1 + 2 = 3.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> cost = [2,3,4,2], time = [1,1,1,1]
|
||||
<strong>Output:</strong> 4
|
||||
<strong>Explanation:</strong> The walls at index 0 and 3 will be painted by the paid painter, and it will take 2 units of time; meanwhile, the free painter will paint the walls at index 1 and 2, free of cost in 2 units of time. Thus, the total cost is 2 + 2 = 4.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= cost.length <= 500</code></li>
|
||||
<li><code>cost.length == time.length</code></li>
|
||||
<li><code>1 <= cost[i] <= 10<sup>6</sup></code></li>
|
||||
<li><code>1 <= time[i] <= 500</code></li>
|
||||
</ul>
|
32
leetcode/problem/special-permutations.html
Normal file
32
leetcode/problem/special-permutations.html
Normal file
@@ -0,0 +1,32 @@
|
||||
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> containing <code>n</code> <strong>distinct</strong> positive integers. A permutation of <code>nums</code> is called special if:</p>
|
||||
|
||||
<ul>
|
||||
<li>For all indexes <code>0 <= i < n - 1</code>, either <code>nums[i] % nums[i+1] == 0</code> or <code>nums[i+1] % nums[i] == 0</code>.</li>
|
||||
</ul>
|
||||
|
||||
<p>Return <em>the total number of special permutations. </em>As the answer could be large, return it <strong>modulo </strong><code>10<sup>9 </sup>+ 7</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [2,3,6]
|
||||
<strong>Output:</strong> 2
|
||||
<strong>Explanation:</strong> [3,6,2] and [2,6,3] are the two special permutations of nums.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,4,3]
|
||||
<strong>Output:</strong> 2
|
||||
<strong>Explanation:</strong> [3,1,4] and [4,1,3] are the two special permutations of nums.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>2 <= nums.length <= 14</code></li>
|
||||
<li><code>1 <= nums[i] <= 10<sup>9</sup></code></li>
|
||||
</ul>
|
37
leetcode/problem/total-distance-traveled.html
Normal file
37
leetcode/problem/total-distance-traveled.html
Normal file
@@ -0,0 +1,37 @@
|
||||
<p>A truck has two fuel tanks. You are given two integers, <code>mainTank</code> representing the fuel present in the main tank in liters and <code>additionalTank</code> representing the fuel present in the additional tank in liters.</p>
|
||||
|
||||
<p>The truck has a mileage of <code>10</code> km per liter. Whenever <code>5</code> liters of fuel get used up in the main tank, if the additional tank has at least <code>1</code> liters of fuel, <code>1</code> liters of fuel will be transferred from the additional tank to the main tank.</p>
|
||||
|
||||
<p>Return <em>the maximum distance which can be traveled.</em></p>
|
||||
|
||||
<p><strong>Note: </strong>Injection from the additional tank is not continuous. It happens suddenly and immediately for every 5 liters consumed.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> mainTank = 5, additionalTank = 10
|
||||
<strong>Output:</strong> 60
|
||||
<strong>Explanation:</strong>
|
||||
After spending 5 litre of fuel, fuel remaining is (5 - 5 + 1) = 1 litre and distance traveled is 50km.
|
||||
After spending another 1 litre of fuel, no fuel gets injected in the main tank and the main tank becomes empty.
|
||||
Total distance traveled is 60km.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> mainTank = 1, additionalTank = 2
|
||||
<strong>Output:</strong> 10
|
||||
<strong>Explanation:</strong>
|
||||
After spending 1 litre of fuel, the main tank becomes empty.
|
||||
Total distance traveled is 10km.
|
||||
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= mainTank, additionalTank <= 100</code></li>
|
||||
</ul>
|
Reference in New Issue
Block a user