The title
You are given two string arrays word1 and word2. Return true if two arrays represent the same string; Otherwise, return false.
The string represented by an array is a sequential concatenation of all the elements in the array.
Example 1: Input: word1 = ["ab", "c"], word2 = ["a", "BC "] Output: true Word1 represents the string "ab" + "C" -> "ABC" Word2 represents the string "A" + "BC" -> "ABC" The two strings are the same, return true Example 2: Enter: Word1 = ["a", "cb"], word2 = ["ab", "c"] Output: false Example 3: Input: word1 = [" ABC ", "d", "defg"], word2 = ["abcddefg"] Output: trueCopy the code
Tip:
1 <= word1.length, word2.length <= 103 1 <= word1[i].length, word2[i].length <= 103 1 <= sum(word1[i].length), Sum (word2[I].length) <= 103 Word1 [I] and word2[I] are lowercase letters
Their thinking
class Solution: def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool: # use the join, Word1Str = "". Join (word1) word2Str = "". Join (word2) return word1Str == word2Str if __name__ == '__main__': word1 = ["ab", "c"] word2 = ["a", "bc"] word1 = ["a", "cb"] word2 = ["ab", "c"] ret = Solution().arrayStringsAreEqual(word1, word2) print(ret)Copy the code