leetcode 1662. Check If Two String Arrays are Equivalent(python)
描述
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)相关推荐
- 【LeetCode】222. Count Complete Tree Nodes 解题报告(Python)
[LeetCode]222. Count Complete Tree Nodes 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个 ...
- 【LeetCode】954. Array of Doubled Pairs 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- 【LeetCode】825. Friends Of Appropriate Ages 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/friends-o ...
- 【LeetCode】528. Random Pick with Weight 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/random-pi ...
- 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 ...
- 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 ...
- python找出只出现一次的数字_【LeetCode 136】只出现一次的数字(Python)
题目:给定一个非空整数数组,除了某个元素只出现一次以外,其余每个元素均出现两次.找出那个只出现了一次的元素. 说明:你的算法应该具有线性时间复杂度. 你可以不使用额外空间来实现吗? 一.思路 通过遍历 ...
- LeetCode:309. 最佳买卖股票时机含冷冻期(python)
LeetCode:309. 最佳买卖股票时机含冷冻期(python) 给定一个整数数组,其中第 i 个元素代表了第 i 天的股票价格 . 设计一个算法计算出最大利润.在满足以下约束条件下,你可以尽可能 ...
- 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 ...
最新文章
- python生成50个随机数_Python:如何生成12位随机数?
- python字典随机取数
- 百度地图API快速调用,一键生成百度地图
- python3的socket_python2 与 python3 socket编程的一点小区别
- 关掉windows自动更新
- android adb 传文件大小,使用adb在电脑和手机间传文件
- 信息系统项目管理师优秀论文:项目范围管理
- 小程序修改数组中对象的某个值或者修改对象值
- vue时间过滤器filter
- idea导入maven项目依赖报错_解决Maven依赖冲突的好帮手,这款IDEA插件了解一下?
- VMWare 全屏后最小化死机
- Android 进程间通信——Service、Messenger
- 超好用的IDEA插件汇总
- python课程开课吧怎么样-开课吧最新廖雪峰Python商业爬虫课程,全套完整课程资源下载...
- Python网络爬虫实现音乐下载器和图片下载器功能
- proteus仿真常见报错信息
- 固态硬盘是什么接口_了解移动固态硬盘接口知识,告诉你PSSD到底能多快
- json校验失败的原因
- 43.属性名和属性值
- 人间简史从动物到上帝读后感_从我的博客到上帝的耳朵...