1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-12 19:01:47 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee

批量更新数据

This commit is contained in:
2025-01-09 20:29:41 +08:00
parent 04ecea043d
commit 48cdd06c2b
5053 changed files with 156164 additions and 135322 deletions

View File

@@ -1,40 +1,53 @@
<p>给定一个函数 <code>fn</code>&nbsp;,一个参数数组 <code>args</code> 和一个以毫秒为单位的超时时间 <code>t</code> ,返回一个取消函数 <code>cancelFn</code></p>
<p>给定一个函数 <code>fn</code>&nbsp;,一个参数数组 <code>args</code> 和一个以毫秒为单位的超时时间 <code>t</code> ,返回一个取消函数 <code>cancelFn</code></p>
<p>经过 <code>t</code> 毫秒的延迟后,应该调用 <code>fn</code> 函数,并将 <code>args</code> 作为参数传递。<strong>除非</strong><code>t</code> 毫秒的延迟过程中,在 <code>cancelT</code> 毫秒时调用了 <code>cancelFn</code>。并且在这种情况下,<code>fn</code> 函数不应该被调用。</p>
<p><code>cancelTimeMs</code>&nbsp;的延迟后,返回的取消函数 <code>cancelFn</code>被调用。</p>
<pre>
setTimeout(cancelFn, cancelTimeMs)
</pre>
<p>最初,函数 <code>fn</code> 的执行应该延迟 <code>t</code> 毫秒。</p>
<p>如果在 <code>t</code> 毫秒的延迟之前调用了函数 <code>cancelFn</code>,它应该取消 <code>fn</code> 的延迟执行。否则,如果在指定的延迟 <code>t</code> 内没有调用 <code>cancelFn</code>,则应执行 <code>fn</code>,并使用提供的 <code>args</code> 作为参数。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1:</strong></p>
<pre>
<b>输入:</b>fn = (x) =&gt; x * 5, args = [2], t = 20, cancelT = 50
<b>输入:</b>fn = (x) =&gt; x * 5, args = [2], t = 20
<b>输出:</b>[{"time": 20, "returned": 10}]
<b>解释:</b>
const cancel = cancellable((x) =&gt; x * 5, [2], 20); // fn(2) 在 t=20ms 时被调用
setTimeout(cancel, 50);
const cancelTimeMs = 50;
const cancelFn = cancellable((x) =&gt; x * 5, [2], 20);
setTimeout(cancelFn, cancelTimeMs);
取消操作被安排在延迟了 cancelT50毫秒后进行这发生在 fn(2) 在20毫秒时执行之后。</pre>
取消操作被安排在延迟了 cancelTimeMs50毫秒后进行这发生在 fn(2) 在20毫秒时执行之后。</pre>
<p><strong class="example">示例 2</strong></p>
<pre>
<b>输入:</b>fn = (x) =&gt; x**2, args = [2], t = 100, cancelT = 50
<b>输入:</b>fn = (x) =&gt; x**2, args = [2], t = 100
<b>输出:</b>[]
<b>解释:</b>
const cancel = cancellable((x) =&gt; x**2, [2], 100); // fn(2) 没被调用
setTimeout(cancel, 50);
const cancelTimeMs = 50;
const cancelFn = cancellable((x) =&gt; x**2, [2], 100);
setTimeout(cancelFn, cancelTimeMs);
取消操作被安排在延迟了 cancelT50毫秒后进行这发生在 fn(2) 在100毫秒时执行之前导致 fn(2) 从未被调用。
取消操作被安排在延迟了 cancelTimeMs50毫秒后进行这发生在 fn(2) 在100毫秒时执行之前导致 fn(2) 从未被调用。
</pre>
<p><strong class="example">示例 3</strong></p>
<pre>
<b>输入:</b>fn = (x1, x2) =&gt; x1 * x2, args = [2,4], t = 30, cancelTime = 100
<b>输入:</b>fn = (x1, x2) =&gt; x1 * x2, args = [2,4], t = 30
<b>输出:</b>[{"time": 30, "returned": 8}]
<b>解释:</b>
const cancel = cancellable((x1, x2) =&gt; x1 * x2, [2,4], 30); // fn(2,4) 在 t=30ms 时被调用
setTimeout(cancel, 100);
const cancelTimeMs = 100;
const cancelFn = cancellable((x1, x2) =&gt; x1 * x2, [2,4], 30);
setTimeout(cancelFn, cancelTimeMs);
取消操作被安排在延迟了 cancelT100毫秒后进行这发生在 fn(2,4) 在30毫秒时执行之后。
取消操作被安排在延迟了 cancelTimeMs100毫秒后进行这发生在 fn(2,4) 在30毫秒时执行之后。
</pre>
<p>&nbsp;</p>
@@ -46,5 +59,5 @@ setTimeout(cancel, 100);
<li><code>args</code> 是一个有效的 JSON 数组</li>
<li><code>1 &lt;= args.length &lt;= 10</code></li>
<li><code><font face="monospace">20 &lt;= t &lt;= 1000</font></code></li>
<li><code><font face="monospace">10 &lt;= cancelT &lt;= 1000</font></code></li>
<li><code><font face="monospace">10 &lt;= cancelTimeMs&nbsp;&lt;= 1000</font></code></li>
</ul>