1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-14 01:49:41 +01:00
LeetCode/problems/rs/longest-increasing-subsequence.rs
Matej Focko 333866d1bc
chore: split solutions by language
Signed-off-by: Matej Focko <mfocko@redhat.com>
2023-06-02 17:19:02 +02:00

18 lines
397 B
Rust

use std::cmp::max;
impl Solution {
pub fn length_of_lis(nums: Vec<i32>) -> i32 {
let mut dp = Vec::<i32>::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()
}
}