当前位置:网站首页>LeetCode 1662. Check whether two string arrays are equal

LeetCode 1662. Check whether two string arrays are equal

2022-06-24 04:51:00 freesan44

subject

Here are two string arrays word1 and word2 . If two arrays represent the same string , return true ; otherwise , return false .

Array representation string   Is made up of all the elements in the array According to the order The string formed by the connection .

 Example  1:

 Input :word1 = ["ab", "c"], word2 = ["a", "bc"]
 Output :true
 explain :
word1  The string represented is  "ab" + "c" -> "abc"
word2  The string represented is  "a" + "bc" -> "abc"
 The two strings are the same , return  true
 Example  2:

 Input :word1 = ["a", "cb"], word2 = ["ab", "c"]
 Output :false
 Example  3:

 Input :word1  = ["abc", "d", "defg"], word2 = ["abcddefg"]
 Output :true

Tips :

1 <= word1.length, word2.length <= 103

1 <= word1i.length, word2i.length <= 103

1 <= sum(word1i.length), sum(word2i.length) <= 103

word1i and word2i It's made up of lowercase letters

Their thinking

class Solution:
    def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
        #  use join, hold list Turn into str
        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)
原网站

版权声明
本文为[freesan44]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/09/20210903184937270m.html