Day 34
Date: November 1, 2022 8:51 AM
LinkedIn: https://leetcode.cn/problems/check-if-two-string-arrays-are-equivalent/description/
Title: 检查两个字符串数组是否相等
class Solution:
def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:
str1 = ''.join(word1)
str2 = ''.join(word2)
return str1 == str2
拼接列表字符串
-
字符串=‘分隔符’.join(列表)
- 如:
words=['a','b','c'] str1=' '.join(words) print(str1) # a b cwords=['a','b','c'] str1=''.join(words) print(str1) # abc

本文介绍了一种简单的方法来判断两个字符串数组是否相等。通过将数组中的所有字符串连接成一个单一的字符串,然后比较这两个合成的字符串是否相同,以此来确定原始数组是否相等。文章还提供了Python代码示例。
8484

被折叠的 条评论
为什么被折叠?



