Rust Solution: Building Length vectors of Longest Matching
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(N)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(N)\n# Code\n```rust []\nimpl Solution {\n    pub fn valid_sequence(word1: String, word2: String) -> Vec<i32> {\n        let m = word2.len();\n        let n = word1.len();\n        let word1 = word1.chars().into_iter().collect::<Vec<char>>();\n        let word2 = word2.chars().into_iter().collect::<Vec<char>>();\n        let mut a = vec![0; n];\n        let mut b = vec![0; n];\n\n        for i in 0 .. n {\n            if i > 0 {\n                a[i] = a[i - 1];\n            }\n            let k = a[i] as usize;\n            if k < m && word2[k] == word1[i] {\n                a[i] += 1;\n            }\n        }\n\n        for i in (0 .. n).rev() {\n            if i + 1 < n {\n                b[i] = b[i + 1];\n            }\n            let k = b[i] as usize;\n            if k < m && word2[m - 1 - k] == word1[i] {\n                b[i] += 1;\n            }\n        }\n\n        let mut ret = vec![];\n\n        for i in 0 .. n {\n            let mut t = 1;\n            \n            if i > 0 {\n                t += a[i - 1];\n            }\n            \n            if i + 1 < n {\n                t += b[i + 1];\n            }\n            \n            if (t as usize) < m {\n                continue \n            }\n            \n            let mut k = 0;\n            if i > 0 {\n                k = a[i - 1] as usize;\n            }\n\n            if ret.is_empty() == false && k < m && word1[i] == word2[k] {\n                continue;\n            }\n\n            let mut data = vec![];\n            for j in 0 .. i {\n                if word1[j] != word2[data.len()] { continue }\n                data.push(j as i32);\n            }\n\n            if data.len() < m { data.push(i as i32); }\n            for j in i + 1 .. n {\n                if data.len() == m { break }\n                if word1[j] != word2[data.len()] { continue }\n                data.push(j as i32);\n            }\n\n            ret.push(data);\n            if ret.len() == 2 { break }\n        }\n\n        if ret.is_empty() { return vec![] }\n        if ret.len() == 1 { return ret[0].clone() }\n        return ret[0].clone().min(ret[1].clone())\n     }\n}\n```
['Rust']