2019-11-10 LeetCode in Rust LeetCode 1143. Longest Common Subsequence Problem Statement impl Solution { pub fn longest_common_subsequence(text1: String, text2: String) -> i32 { let (m, n, mut i, mut j) = (text1.len(), text2.len(), 0, 0); let mut dp = vec![vec![0; n + 1]; m + 1]; while i < m { while j < n { if text1.chars().nth(i).unwrap() == text2.chars().nth(j).unwrap() { dp[i + 1][j + 1] = dp[i][j] + 1; } else { dp[i + 1][j + 1] = std::cmp::max(dp[i][j + 1], dp[i + 1][j]); } j += 1; } i += 1; } return dp[m][n]; }} Newer LeetCode 1138. Alphabet Board Path Older LeetCode 1144. Decrease Elements To Make Array Zigzag