Skip to content

Commit

Permalink
[LeetCode] Add January 15.
Browse files Browse the repository at this point in the history
  • Loading branch information
pin3da authored Jan 15, 2021
1 parent 79a9809 commit 8b1b548
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions solved/LeetCode/Challenges/2020/January/15.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Solution {
fun getMaximumGenerated(n: Int): Int {
if (n <= 1) {
return n
}
var nums = Array<Int>(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
}
}

0 comments on commit 8b1b548

Please sign in to comment.