1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/复合函数 [function-composition].html

53 lines
1.7 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>请你编写一个函数,它接收一个函数数组 <code>[f<sub>1</sub>, f<sub>2</sub>, f<sub>3</sub>,…, f<sub>n</sub>]</code> ,并返回一个新的函数 <code>fn</code>&nbsp;,它是函数数组的 <strong>复合函数</strong></p>
<p><code>[f(x) g(x) h(x)]</code><strong>复合函数</strong><code>fn(x) = f(g(h(x)))</code>&nbsp;</p>
<p>一个空函数列表的 <strong>复合函数</strong><strong>恒等函数</strong> <code>f(x) = x</code></p>
<p>你可以假设数组中的每个函数接受一个整型参数作为输入,并返回一个整型作为输出。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<pre>
<strong>输入:</strong>functions = [x =&gt; x + 1, x =&gt; x * x, x =&gt; 2 * x], x = 4
<b>输出:</b>65
<strong>解释:</strong>
从右向左计算......
Starting with x = 4.
2 * (4) = 8
(8) * (8) = 64
(64) + 1 = 65
</pre>
<p><strong class="example">示例 2</strong></p>
<pre>
<b>输出:</b>functions = [x =&gt; 10 * x, x =&gt; 10 * x, x =&gt; 10 * x], x = 1
<b>输入:</b>1000
<strong>解释:</strong>
从右向左计算......
10 * (1) = 10
10 * (10) = 100
10 * (100) = 1000
</pre>
<p><strong class="example">示例 3</strong></p>
<pre>
<b>输入:</b>functions = [], x = 42
<b>输出:</b>42
<strong>解释:</strong>
空函数列表的复合函数就是恒等函数</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code><font face="monospace">-1000 &lt;= x &lt;= 1000</font></code></li>
<li><code><font face="monospace">0 &lt;= functions.length &lt;= 1000</font></code></li>
<li><font face="monospace">所有函数都接受并返回一个整型</font></li>
</ul>