mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-11 02:11:42 +08:00
存量题库数据更新
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
<p>给你一个数组 <code>nums</code><em> </em>和一个值 <code>val</code>,你需要 <strong><a href="https://baike.baidu.com/item/%E5%8E%9F%E5%9C%B0%E7%AE%97%E6%B3%95" target="_blank">原地</a></strong> 移除所有数值等于 <code>val</code><em> </em>的元素,并返回移除后数组的新长度。</p>
|
||||
<p>给你一个数组 <code>nums</code><em> </em>和一个值 <code>val</code>,你需要 <strong><a href="https://baike.baidu.com/item/%E5%8E%9F%E5%9C%B0%E7%AE%97%E6%B3%95" target="_blank">原地</a></strong> 移除所有数值等于 <code>val</code><em> </em>的元素,并返回移除后数组的新长度。</p>
|
||||
|
||||
<p>不要使用额外的数组空间,你必须仅使用 <code>O(1)</code> 额外空间并 <strong><a href="https://baike.baidu.com/item/%E5%8E%9F%E5%9C%B0%E7%AE%97%E6%B3%95" target="_blank">原地 </a>修改输入数组</strong>。</p>
|
||||
|
||||
<p>元素的顺序可以改变。你不需要考虑数组中超出新长度后面的元素。</p>
|
||||
|
||||
<p> </p>
|
||||
<p> </p>
|
||||
|
||||
<p><strong>说明:</strong></p>
|
||||
|
||||
@@ -20,35 +20,35 @@ int len = removeElement(nums, val);
|
||||
|
||||
// 在函数里修改输入数组对于调用者是可见的。
|
||||
// 根据你的函数返回的长度, 它会打印出数组中<strong> 该长度范围内</strong> 的所有元素。
|
||||
for (int i = 0; i < len; i++) {
|
||||
print(nums[i]);
|
||||
for (int i = 0; i < len; i++) {
|
||||
print(nums[i]);
|
||||
}
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>nums = [3,2,2,3], val = 3
|
||||
<strong>输出:</strong>2, nums = [2,2]
|
||||
<strong>解释:</strong>函数应该返回新的长度 <strong>2</strong>, 并且 nums<em> </em>中的前两个元素均为 <strong>2</strong>。你不需要考虑数组中超出新长度后面的元素。例如,函数返回的新长度为 2 ,而 nums = [2,2,3,3] 或 nums = [2,2,0,0],也会被视作正确答案。
|
||||
<strong>解释:</strong>函数应该返回新的长度 <strong><code>2</code></strong>, 并且 nums<em> </em>中的前两个元素均为 <strong>2</strong>。你不需要考虑数组中超出新长度后面的元素。例如,函数返回的新长度为 2 ,而 nums = [2,2,3,3] 或 nums = [2,2,0,0],也会被视作正确答案。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>nums = [0,1,2,2,3,0,4,2], val = 2
|
||||
<strong>输出:</strong>5, nums = [0,1,4,0,3]
|
||||
<strong>解释:</strong>函数应该返回新的长度 <strong><code>5</code></strong>, 并且 nums 中的前五个元素为 <strong><code>0</code></strong>, <strong><code>1</code></strong>, <strong><code>3</code></strong>, <strong><code>0</code></strong>, <strong>4</strong>。注意这五个元素可为任意顺序。你不需要考虑数组中超出新长度后面的元素。
|
||||
<strong>输出:</strong>5, nums = [0,1,3,0,4]
|
||||
<strong>解释:</strong>函数应该返回新的长度 <strong><code>5</code></strong>, 并且 nums 中的前五个元素为 <strong><code>0</code></strong>, <strong><code>1</code></strong>, <strong><code>3</code></strong>, <strong><code>0</code></strong>, <strong><code>4</code></strong>。注意这五个元素可为任意顺序。你不需要考虑数组中超出新长度后面的元素。
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>0 <= nums.length <= 100</code></li>
|
||||
<li><code>0 <= nums[i] <= 50</code></li>
|
||||
<li><code>0 <= val <= 100</code></li>
|
||||
<li><code>0 <= nums.length <= 100</code></li>
|
||||
<li><code>0 <= nums[i] <= 50</code></li>
|
||||
<li><code>0 <= val <= 100</code></li>
|
||||
</ul>
|
||||
|
Reference in New Issue
Block a user