[
string
]
Leetcode 1662. Check If Two String Arrays are Equivalent
https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent
What we need to do in this problem is just check if concatenation of first group of strings is equal to concatenation of the second group of strings. We can do it in O(1)
space if we go symbol by symbol, however we need to keep indexes and so on. The easiest way to solve this problem in pythin is just to use join()
function: ""
means that when we join strings we do not add anything between them.
Complexity: time and space complexity is O(n+m)
, where n
and m
are total sums of strings in the first and in the second groups.
class Solution:
def arrayStringsAreEqual(self, word1, word2):
return "".join(word1) == "".join(word2)
If you like the solution, you can upvote it on leetcode discussion section: Problem 1662