[Leet Code] Check If Two String Arrays Are Equivalent

Matthew Boyd
1 min readNov 25, 2020

Leetcode: https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/

Problem:

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:

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.

Solution:

class Solution(object):
def arrayStringsAreEqual(self, word1, word2):
"""
:type word1: List[str]
:type word2: List[str]
:rtype: bool
"""
word1full = ""
word2full = ""
for i in range(len(word1)):
word1full += "".join(word1[i])
for i in range(len(word2)):
word2full += "".join(word2[i])
if word1full == word2full:
return True
else:
return False

--

--