前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >LeetCode 1662. 检查两个字符串数组是否相等

LeetCode 1662. 检查两个字符串数组是否相等

原创
作者头像
freesan44
修改2021-09-03 18:07:30
7980
修改2021-09-03 18:07:30
举报
文章被收录于专栏:freesan44freesan44

题目

给你两个字符串数组 word1 和 word2 。如果两个数组表示的字符串相同,返回 true ;否则,返回 false 。

数组表示的字符串 是由数组中的所有元素 按顺序 连接形成的字符串。

代码语言:txt
复制
示例 1:

输入:word1 = ["ab", "c"], word2 = ["a", "bc"]
输出:true
解释:
word1 表示的字符串为 "ab" + "c" -> "abc"
word2 表示的字符串为 "a" + "bc" -> "abc"
两个字符串相同,返回 true
示例 2:

输入:word1 = ["a", "cb"], word2 = ["ab", "c"]
输出:false
示例 3:

输入:word1  = ["abc", "d", "defg"], word2 = ["abcddefg"]
输出:true

提示:

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

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

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

word1i 和 word2i 由小写字母组成

解题思路

代码语言:txt
复制
class Solution:
    def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
        # 用join,把list转成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)

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 题目
  • 解题思路
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档