1662. Check if two string arrays are equal
Easy difficulty 6
Gives you the
word1
sum of two string arraysword2
. If the strings represented by the two arrays are the same, return ; otherwise, return .true
false
The string represented by the array is a string formed by concatenating all the elements in the array in order .
Example 1:
输入:word1 = ["ab", "c"], word2 = ["a", "bc"] 输出:true 解释: word1 表示的字符串为 "ab" + "c" -> "abc" word2 表示的字符串为 "a" + "bc" -> "abc" 两个字符串相同,返回 true
Example 2:
输入:word1 = ["a", "cb"], word2 = ["ab", "c"] 输出:false
Example 3:
输入:word1 = ["abc", "d", "defg"], word2 = ["abcddefg"] 输出:true
prompt:
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]
Andword2[i]
consists of lowercase letters
class Solution {
public:
bool arrayStringsAreEqual(vector<string>& word1, vector<string>& word2) {
string str1, str2;
for(auto str: word1){
str1 += str;
}
for(auto str: word2){
str2 += str;
}
return str1 == str2;
}
};