描述

Given two string arrays word1 and word2, return true if the two arrays represent the same string, and false otherwise.

A string is represented by an array if the array elements concatenated in order forms the string.

Example 1:

Input: word1 = ["ab", "c"], word2 = ["a", "bc"]
Output: true
Explanation:
word1 represents string "ab" + "c" -> "abc"
word2 represents string "a" + "bc" -> "abc"
The strings are the same, so return true.

Example 2:

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

Example 3:

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

Note:

  • 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] consist of lowercase letters.

解析

根据题意,只需要将 word1 和 word2 按照顺序将元素拼接起来形成字符串进行比较即可,相等为 true ,否则为 false

解答

class Solution(object):def arrayStringsAreEqual(self, word1, word2):""":type word1: List[str]:type word2: List[str]:rtype: bool"""return "".join(word1) == "".join(word2)

运行结果

Runtime: 16 ms, faster than 91.14% of Python online submissions for Check If Two String Arrays are Equivalent.
Memory Usage: 13.5 MB, less than 53.17% of Python online submissions for Check If Two String Arrays are Equivalent.

原题链接:https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/

leetcode 1662. Check If Two String Arrays are Equivalent(python)相关推荐

  1. 【LeetCode】222. Count Complete Tree Nodes 解题报告(Python)

    [LeetCode]222. Count Complete Tree Nodes 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个 ...

  2. 【LeetCode】954. Array of Doubled Pairs 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  3. 【LeetCode】825. Friends Of Appropriate Ages 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/friends-o ...

  4. 【LeetCode】528. Random Pick with Weight 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/random-pi ...

  5. LeetCode 1011. Capacity To Ship Packages Within D Days(python)

    1011. Capacity To Ship Packages Within D Days Capacity To Ship Packages Within D Days python solutio ...

  6. leetcode 1005. Maximize Sum Of Array After K Negations(python)

    描述 Given an array nums of integers, we must modify the array in the following way: we choose an i an ...

  7. python找出只出现一次的数字_【LeetCode 136】只出现一次的数字(Python)

    题目:给定一个非空整数数组,除了某个元素只出现一次以外,其余每个元素均出现两次.找出那个只出现了一次的元素. 说明:你的算法应该具有线性时间复杂度. 你可以不使用额外空间来实现吗? 一.思路 通过遍历 ...

  8. LeetCode:309. 最佳买卖股票时机含冷冻期(python)

    LeetCode:309. 最佳买卖股票时机含冷冻期(python) 给定一个整数数组,其中第 i 个元素代表了第 i 天的股票价格 . 设计一个算法计算出最大利润.在满足以下约束条件下,你可以尽可能 ...

  9. LeetCode 1430. Check If a String Is a Valid Sequence from Root to Leaves Path in a Binary Tree

    [Med] LeetCode 1430. Check If a String Is a Valid Sequence from Root to Leaves Path in a Binary Tree ...

最新文章

  1. python生成50个随机数_Python:如何生成12位随机数?
  2. python字典随机取数
  3. 百度地图API快速调用,一键生成百度地图
  4. python3的socket_python2 与 python3 socket编程的一点小区别
  5. 关掉windows自动更新
  6. android adb 传文件大小,使用adb在电脑和手机间传文件
  7. 信息系统项目管理师优秀论文:项目范围管理
  8. 小程序修改数组中对象的某个值或者修改对象值
  9. vue时间过滤器filter
  10. idea导入maven项目依赖报错_解决Maven依赖冲突的好帮手,这款IDEA插件了解一下?
  11. VMWare 全屏后最小化死机
  12. Android 进程间通信——Service、Messenger
  13. 超好用的IDEA插件汇总
  14. python课程开课吧怎么样-开课吧最新廖雪峰Python商业爬虫课程,全套完整课程资源下载...
  15. Python网络爬虫实现音乐下载器和图片下载器功能
  16. proteus仿真常见报错信息
  17. 固态硬盘是什么接口_了解移动固态硬盘接口知识,告诉你PSSD到底能多快
  18. json校验失败的原因
  19. 43.属性名和属性值
  20. 人间简史从动物到上帝读后感_从我的博客到上帝的耳朵...

热门文章

  1. 如何挖掘客户的潜在需求?
  2. Android 自定义SeekBar 的thumb遮挡问题解决
  3. 51智能小车黑线寻迹(防出线)
  4. C语言中指针类型的意义
  5. Linux系统忘记密码解决办法
  6. Basler 相机硬触发(line1外部触发)接线与输出Out1
  7. oracle表空间扩容asm,oracle表空间文件系统迁移到ASM
  8. HMS Core使能AI智慧体验,共建创新应用生态
  9. CSS样式属性margin,padding详解
  10. oracle 视图编辑保存,oracle 视图