1646 Get Maximum in Generated Array
You are given an integer n
. An array nums
of length n + 1
is generated in the following way:
nums[0] = 0
nums[1] = 1
nums[2 * i] = nums[i]
when2 <= 2 * i <= n
nums[2 * i + 1] = nums[i] + nums[i + 1]
when2 <= 2 * i + 1 <= n
Return the maximum integer in the array nums
.
Example 1:
Example 2:
Example 3:
Constraints:
0 <= n <= 100
You are given an integer
n
. An arraynums
of lengthn + 1
is generated in the following way:nums[0] = 0
nums[1] = 1
nums[2 * i] = nums[i]
when2 <= 2 * i <= n
nums[2 * i + 1] = nums[i] + nums[i + 1]
when2 <= 2 * i + 1 <= n
Return the maximum integer in the array
nums
.Example 1:
Example 2:
Example 3:
Constraints:
0 <= n <= 100
其实这题有点迷,一看上去,是不是斐波那契数列?然后再看了看,是不是heap?各种想,怎么省空间,算值。然后一看n最大只是100。那,就真的很简单了,其实不懂这题想考什么。规律从第一个例子里就能看出来。T:O(n), S:O(n)
Last updated