Created
August 1, 2020 06:44
-
-
Save charlieInDen/f3d9693c8452a6f7ce9057ef6515fd83 to your computer and use it in GitHub Desktop.
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
func lengthOfLIS(_ nums: [Int]) -> Int { | |
if nums.isEmpty { return 0 } | |
let len = nums.count | |
var dp = Array(repeating: 0, count: len) | |
dp[0] = 1 | |
var ans = 1 | |
for i in 1..<dp.count { | |
var maxVal = 0 | |
for j in 0..<i { | |
if nums[i] > nums[j] { | |
maxVal = max(maxVal, dp[j]) | |
} | |
} | |
dp[i] = maxVal + 1 | |
ans = max(ans, dp[i]) | |
} | |
return ans | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment