Created
July 19, 2024 19:09
-
-
Save WhiteHyun/b2344c0fa3425cd5333d1a2a32498d37 to your computer and use it in GitHub Desktop.
LeetCode - 300. Longest Increasing Subsequence using DP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final class Solution { | |
func lengthOfLIS(_ nums: [Int]) -> Int { | |
var dp: [Int] = .init(repeating: 1, count: nums.count) | |
for i in 1..<nums.count { | |
for j in 0..<i where dp[i] <= dp[j] && nums[j] < nums[i] { | |
dp[i] = dp[j] + 1 | |
} | |
} | |
return dp.max() ?? 1 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment