Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save WhiteHyun/b2344c0fa3425cd5333d1a2a32498d37 to your computer and use it in GitHub Desktop.
Save WhiteHyun/b2344c0fa3425cd5333d1a2a32498d37 to your computer and use it in GitHub Desktop.
LeetCode - 300. Longest Increasing Subsequence using DP
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