https://leetcode-cn.com/problems/get-maximum-in-generated-array/
模拟。
最近力扣每日一题打卡有很多的模拟题啊🤔, 其实我之前没怎么做过模拟题啦。
但是最近练了不少。
这道题题干基本把信息都给出来了就不仔细分析了。
class Solution:
def getMaximumGenerated(self, n: int) -> int:
if not n:
return 0
nums = [0 for i in range(n + 1)]
nums[1] = 1
for i in range(1, n + 1):
if 2 <= 2 * i <= n:
nums[2*i] = nums[i]
if 2 <= 2 * i + 1 <= n:
nums[2*i + 1] = nums[i] + nums[i + 1]
return max(nums)- 时间复杂度: O(n)
- 空间复杂度: O(n)

