Given two string arrays word1 and word2, return true if the two arrays represent the same string, and false otherwise. An array represents the string formed by concatenating its elements in order.
Given two string arrays word1 and word2, return true if the two arrays represent the same string, and false otherwise. An array represents the string formed by concatenating its elements in order.
Example 1:
Input: {"word1":["ab","c"],"word2":["a","bc"]}
Output: true
Constraints:
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.
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"word1":["ab","c"],"word2":["a","bc"]}
Instead of building both strings, walk them in place. (w1, c1) points at a character inside word1, (w2, c2) at one inside word2.
both arrays laid end to end
word1: piece 0, char 0
a
b
c
▼▲
1
2
word2: piece 0, char 0
a
b
c
amber ticks = where each array cuts its pieces; the cuts never need to line up