mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 19:53:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			53 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			53 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>请你编写一个函数,它接收一个函数数组 <code>[f<sub>1</sub>, f<sub>2</sub>, f<sub>3</sub>,…, f<sub>n</sub>]</code> ,并返回一个新的函数 <code>fn</code> ,它是函数数组的 <strong>复合函数</strong> 。</p>
 | 
						||
 | 
						||
<p><code>[f(x), g(x), h(x)]</code> 的 <strong>复合函数</strong> 为 <code>fn(x) = f(g(h(x)))</code> 。</p>
 | 
						||
 | 
						||
<p>一个空函数列表的 <strong>复合函数</strong> 是 <strong>恒等函数</strong> <code>f(x) = x</code> 。</p>
 | 
						||
 | 
						||
<p>你可以假设数组中的每个函数接受一个整型参数作为输入,并返回一个整型作为输出。</p>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong class="example">示例 1:</strong></p>
 | 
						||
 | 
						||
<pre>
 | 
						||
<strong>输入:</strong>functions = [x => x + 1, x => x * x, x => 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 => 10 * x, x => 10 * x, x => 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> </p>
 | 
						||
 | 
						||
<p><strong>提示:</strong></p>
 | 
						||
 | 
						||
<ul>
 | 
						||
	<li><code><font face="monospace">-1000 <= x <= 1000</font></code></li>
 | 
						||
	<li><code><font face="monospace">0 <= functions.length <= 1000</font></code></li>
 | 
						||
	<li><font face="monospace">所有函数都接受并返回一个整型</font></li>
 | 
						||
</ul>
 |