Get Maximum in Generated Array
You are given an integer n. A 0-indexed integer array nums of length n + 1 is generated in the following way:
nums[0] = 0nums[1] = 1nums[2 * i] = nums[i]when2 <= 2 * i <= nnums[2 * i + 1] = nums[i] + nums[i + 1]when2 <= 2 * i + 1 <= n
Return the maximum integer in the array nums.
Example 1
Input
n = 7Output
3According to the given rules, nums = [0,1,1,2,1,3,2,3], and the maximum is 3.
Example 2
Input
n = 2Output
1According to the given rules, nums = [0,1,1], and the maximum is 1.
Constraints
- 0 <= n <= 100