diff --git a/problems/longest-increasing-subsequence.rs b/problems/longest-increasing-subsequence.rs new file mode 100644 index 0000000..a269416 --- /dev/null +++ b/problems/longest-increasing-subsequence.rs @@ -0,0 +1,18 @@ +use std::cmp::max; + +impl Solution { + pub fn length_of_lis(nums: Vec) -> i32 { + let mut dp = Vec::::new(); + dp.resize(nums.len(), 1); + + for i in 1..nums.len() { + for j in 0..i { + if nums[i] > nums[j] { + dp[i] = max(dp[i], dp[j] + 1); + } + } + } + + *dp.iter().max().unwrap() + } +}