|
| 1 | +/** |
| 2 | + * [1662] Check If Two String Arrays are Equivalent |
| 3 | + * |
| 4 | + * Given two string arrays word1 and word2, return true if the two arrays represent the same string, and false otherwise. |
| 5 | + * A string is represented by an array if the array elements concatenated in order forms the string. |
| 6 | + * |
| 7 | + * Example 1: |
| 8 | + * |
| 9 | + * Input: word1 = ["ab", "c"], word2 = ["a", "bc"] |
| 10 | + * Output: true |
| 11 | + * Explanation: |
| 12 | + * word1 represents string "ab" + "c" -> "abc" |
| 13 | + * word2 represents string "a" + "bc" -> "abc" |
| 14 | + * The strings are the same, so return true. |
| 15 | + * Example 2: |
| 16 | + * |
| 17 | + * Input: word1 = ["a", "cb"], word2 = ["ab", "c"] |
| 18 | + * Output: false |
| 19 | + * |
| 20 | + * Example 3: |
| 21 | + * |
| 22 | + * Input: word1 = ["abc", "d", "defg"], word2 = ["abcddefg"] |
| 23 | + * Output: true |
| 24 | + * |
| 25 | + * |
| 26 | + * Constraints: |
| 27 | + * |
| 28 | + * 1 <= word1.length, word2.length <= 10^3 |
| 29 | + * 1 <= word1[i].length, word2[i].length <= 10^3 |
| 30 | + * 1 <= sum(word1[i].length), sum(word2[i].length) <= 10^3 |
| 31 | + * word1[i] and word2[i] consist of lowercase letters. |
| 32 | + * |
| 33 | + */ |
| 34 | +pub struct Solution {} |
| 35 | + |
| 36 | +// problem: https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/ |
| 37 | +// discuss: https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/discuss/?currentPage=1&orderBy=most_votes&query= |
| 38 | + |
| 39 | +// submission codes start here |
| 40 | + |
| 41 | +impl Solution { |
| 42 | + pub fn array_strings_are_equal(word1: Vec<String>, word2: Vec<String>) -> bool { |
| 43 | + word1.concat() == word2.concat() |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +// submission codes end |
| 48 | + |
| 49 | +#[cfg(test)] |
| 50 | +mod tests { |
| 51 | + use super::*; |
| 52 | + |
| 53 | + #[test] |
| 54 | + fn test_1662_example_1() { |
| 55 | + let word1 = vec_string!["ab", "c"]; |
| 56 | + let word2 = vec_string!["a", "bc"]; |
| 57 | + |
| 58 | + let result = true; |
| 59 | + |
| 60 | + assert_eq!(Solution::array_strings_are_equal(word1, word2), result); |
| 61 | + } |
| 62 | + |
| 63 | + #[test] |
| 64 | + fn test_1662_example_2() { |
| 65 | + let word1 = vec_string!["a", "cb"]; |
| 66 | + let word2 = vec_string!["ab", "c"]; |
| 67 | + |
| 68 | + let result = false; |
| 69 | + |
| 70 | + assert_eq!(Solution::array_strings_are_equal(word1, word2), result); |
| 71 | + } |
| 72 | + |
| 73 | + #[test] |
| 74 | + fn test_1662_example_3() { |
| 75 | + let word1 = vec_string!["abc", "d", "defg"]; |
| 76 | + let word2 = vec_string!["abcddefg"]; |
| 77 | + |
| 78 | + let result = true; |
| 79 | + |
| 80 | + assert_eq!(Solution::array_strings_are_equal(word1, word2), result); |
| 81 | + } |
| 82 | +} |
0 commit comments