mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-12 19:01:47 +08:00
批量更新数据
This commit is contained in:
@@ -1,38 +1,67 @@
|
||||
<p>You are given an array <code>nums</code> of length <code>n</code> and an integer <code>m</code>. You need to determine if it is possible to split the array into <code>n</code> <strong>non-empty</strong> arrays by performing a series of steps.</p>
|
||||
<p>You are given an array <code>nums</code> of length <code>n</code> and an integer <code>m</code>. You need to determine if it is possible to split the array into <code>n</code> arrays of size 1 by performing a series of steps.</p>
|
||||
|
||||
<p>In each step, you can select an existing array (which may be the result of previous steps) with a length of <strong>at least two</strong> and split it into <strong>two </strong>subarrays, if, <strong>for each </strong>resulting subarray, <strong>at least</strong> one of the following holds:</p>
|
||||
<p>An array is called <strong>good</strong> if:</p>
|
||||
|
||||
<ul>
|
||||
<li>The length of the subarray is one, or</li>
|
||||
<li>The sum of elements of the subarray is <strong>greater than or equal</strong> to <code>m</code>.</li>
|
||||
<li>The length of the array is <strong>one</strong>, or</li>
|
||||
<li>The sum of the elements of the array is <strong>greater than or equal</strong> to <code>m</code>.</li>
|
||||
</ul>
|
||||
|
||||
<p>Return <code>true</code><em> if you can split the given array into </em><code>n</code><em> arrays, otherwise return</em> <code>false</code>.</p>
|
||||
<p>In each step, you can select an existing array (which may be the result of previous steps) with a length of <strong>at least two</strong> and split it into <strong>two </strong>arrays, if both resulting arrays are good.</p>
|
||||
|
||||
<p><strong>Note:</strong> A subarray is <em>a contiguous non-empty sequence of elements within an array</em>.</p>
|
||||
<p>Return true if you can split the given array into <code>n</code> arrays, otherwise return false.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [2, 2, 1], m = 4
|
||||
<strong>Output:</strong> true
|
||||
<strong>Explanation:</strong> We can split the array into [2, 2] and [1] in the first step. Then, in the second step, we can split [2, 2] into [2] and [2]. As a result, the answer is true.</pre>
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [2, 2, 1], m = 4</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">true</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li>Split <code>[2, 2, 1]</code> to <code>[2, 2]</code> and <code>[1]</code>. The array <code>[1]</code> has a length of one, and the array <code>[2, 2]</code> has the sum of its elements equal to <code>4 >= m</code>, so both are good arrays.</li>
|
||||
<li>Split <code>[2, 2]</code> to <code>[2]</code> and <code>[2]</code>. both arrays have the length of one, so both are good arrays.</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [2, 1, 3], m = 5
|
||||
<strong>Output:</strong> false
|
||||
<strong>Explanation: </strong>We can try splitting the array in two different ways: the first way is to have [2, 1] and [3], and the second way is to have [2] and [1, 3]. However, both of these ways are not valid. So, the answer is false.</pre>
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [2, 1, 3], m = 5</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">false</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<p>The first move has to be either of the following:</p>
|
||||
|
||||
<ul>
|
||||
<li>Split <code>[2, 1, 3]</code> to <code>[2, 1]</code> and <code>[3]</code>. The array <code>[2, 1]</code> has neither length of one nor sum of elements greater than or equal to <code>m</code>.</li>
|
||||
<li>Split <code>[2, 1, 3]</code> to <code>[2]</code> and <code>[1, 3]</code>. The array <code>[1, 3]</code> has neither length of one nor sum of elements greater than or equal to <code>m</code>.</li>
|
||||
</ul>
|
||||
|
||||
<p>So as both moves are invalid (they do not divide the array into two good arrays), we are unable to split <code>nums</code> into <code>n</code> arrays of size 1.</p>
|
||||
</div>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [2, 3, 3, 2, 3], m = 6
|
||||
<strong>Output:</strong> true
|
||||
<strong>Explanation:</strong> We can split the array into [2, 3, 3, 2] and [3] in the first step. Then, in the second step, we can split [2, 3, 3, 2] into [2, 3, 3] and [2]. Then, in the third step, we can split [2, 3, 3] into [2] and [3, 3]. And in the last step we can split [3, 3] into [3] and [3]. As a result, the answer is true.
|
||||
</pre>
|
||||
<div class="example-block">
|
||||
<p><strong>Input:</strong> <span class="example-io">nums = [2, 3, 3, 2, 3], m = 6</span></p>
|
||||
|
||||
<p><strong>Output:</strong> <span class="example-io">true</span></p>
|
||||
|
||||
<p><strong>Explanation:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><span class="example-io">Split <code>[2, 3, 3, 2, 3]</code> to <code>[2]</code> and <code>[3, 3, 2, 3]</code>.</span></li>
|
||||
<li><span class="example-io">Split <code>[3, 3, 2, 3]</code> to <code>[3, 3, 2]</code> and <code>[3]</code>.</span></li>
|
||||
<li><span class="example-io">Split <code>[3, 3, 2]</code> to <code>[3, 3]</code> and <code>[2]</code>.</span></li>
|
||||
<li><span class="example-io">Split <code>[3, 3]</code> to <code>[3]</code> and <code>[3]</code>.</span></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
Reference in New Issue
Block a user