diff --git a/solved/LeetCode/Challenges/2020/January/15.kt b/solved/LeetCode/Challenges/2020/January/15.kt new file mode 100644 index 00000000..89c66724 --- /dev/null +++ b/solved/LeetCode/Challenges/2020/January/15.kt @@ -0,0 +1,21 @@ +class Solution { + fun getMaximumGenerated(n: Int): Int { + if (n <= 1) { + return n + } + var nums = Array(n+1) {0} + nums[1] = 1 + nums[2] = 1 + for (i in 1..n) { + var next = 2 * i + if (next <= n) { + nums[next] = nums[i] + } + next++ + if (next <= n) { + nums[next] = nums[i] + nums[i + 1] + } + } + return nums.max() ?: 0 + } +}