[LeetCode] Check If Two String Arrays are Equivalent

1662. Check If Two String Arrays are Equivalent

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
class Solution {
public:
bool arrayStringsAreEqual(vector<string>& A, vector<string>& B) {
while(A.size() and B.size()) {
if(A.back().back() != B.back().back()) return false;
A.back().pop_back();
B.back().pop_back();
if(A.back().empty()) A.pop_back();
if(B.back().empty()) B.pop_back();
}
return A.empty() and B.empty();
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2022/10/25/PS/LeetCode/check-if-two-string-arrays-are-equivalent/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.