给你两个字符串数组 word1 和 word2 。如果两个数组表示的字符串相同,返回 true ;否则,返回 false 。数组表示的字符串 是由数组中的所有元素 按顺序 连接形成的字符串。

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

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

示例 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 <= word1[i].length, word2[i].length <= 103
  • 1 <= sum(word1[i].length), sum(word2[i].length) <= 103
  • word1[i] 和 word2[i] 由小写字母组成

class Solution:

    def arrayStringsAreEqual(self, word1: List[str], word2: List[str]) -> bool:

        return ''.join(word1) == ''.join(word2)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是两种判断给定字符串是否为回文的方法: 1.使用循环比较字符串的前后字符是否相同,计数是否占总字符数的一半来判断是否为回文。 ```c #include <stdio.h> #include <string.h> int main() { char str[80]; int i, count = 0; int t = 0; gets(str);//输入 count = strlen(str);//统计共有多少个字符 for (i = 0; i < count / 2; i++)//比较总字符数1/2次 { if (str[i] == str[count - 1 - i]) t++;//若相同,就计数一次 } if (i == t)//若累计计数达到字符串长度的一半,就是回文 printf("%s是回文\n", str); else printf("%s不是回文\n", str); return 0; } ``` 2.使用栈来判断给定字符串是否为回文。 ```javascript /*使用栈stack类的实现*/ function stack() { this.dataStore = [];//保存栈内元素,初始化为一个空数组 this.top = 0;//栈顶位置,初始化为0 this.push = push;//入栈 this.pop = pop;//出栈 this.peek = peek;//查看栈顶元素 this.clear = clear;//清空栈 this.length = length;//获取栈内元素个数 } function push(element) { this.dataStore[this.top++] = element; } function pop() { return this.dataStore[--this.top]; } function peek() { return this.dataStore[this.top - 1]; } function clear() { this.top = 0; } function length() { return this.top; } function isPalindrome(word) { var s = new stack(); for (var i = 0; i < word.length; ++i) { s.push(word[i]); } var rword = ""; while (s.length() > 0) { rword += s.pop(); } if (word == rword) { return true; } else { return false; } } var word = "racecar"; if (isPalindrome(word)) { console.log(word + " is a palindrome."); } else { console.log(word + " is not a palindrome."); } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值