Skip to content

Commit c518708

Browse files
committed
day 8
1 parent ba41f98 commit c518708

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
Check If Two String Arrays are Equivalent
3+
===========================================
4+
5+
Given two string arrays word1 and word2, return true if the two arrays represent the same string, and false otherwise.
6+
7+
A string is represented by an array if the array elements concatenated in order forms the string.
8+
9+
Example 1:
10+
Input: word1 = ["ab", "c"], word2 = ["a", "bc"]
11+
Output: true
12+
Explanation:
13+
word1 represents string "ab" + "c" -> "abc"
14+
word2 represents string "a" + "bc" -> "abc"
15+
The strings are the same, so return true.
16+
17+
Example 2:
18+
Input: word1 = ["a", "cb"], word2 = ["ab", "c"]
19+
Output: false
20+
21+
Example 3:
22+
Input: word1 = ["abc", "d", "defg"], word2 = ["abcddefg"]
23+
Output: true
24+
25+
Constraints:
26+
1 <= word1.length, word2.length <= 103
27+
1 <= word1[i].length, word2[i].length <= 103
28+
1 <= sum(word1[i].length), sum(word2[i].length) <= 103
29+
word1[i] and word2[i] consist of lowercase letters.
30+
31+
Hint #1
32+
Concatenate all strings in the first array into a single string in the given order, the same for the second array.
33+
34+
Hint #2
35+
Both arrays represent the same string if and only if the generated strings are the same.
36+
*/
37+
38+
class Solution
39+
{
40+
public:
41+
bool arrayStringsAreEqual(vector<string> &word1, vector<string> &word2)
42+
{
43+
string a, b;
44+
45+
for (auto &i : word1)
46+
a += i;
47+
for (auto &i : word2)
48+
b += i;
49+
50+
return a == b;
51+
}
52+
};

Leetcode Daily Challenge/January-2021/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@
99
| 5. | [Remove Duplicates from Sorted List II](https://leetcode.com/explore/challenge/card/january-leetcoding-challenge-2021/579/week-1-january-1st-january-7th/3593/) | [cpp](./05.%20Remove%20Duplicates%20from%20Sorted%20List%20II.cpp) |
1010
| 6. | [Kth Missing Positive Number](https://leetcode.com/explore/challenge/card/january-leetcoding-challenge-2021/579/week-1-january-1st-january-7th/3594/) | [cpp](./06.%20Kth%20Missing%20Positive%20Number.cpp) |
1111
| 7. | [Longest Substring Without Repeating Characters](https://leetcode.com/explore/challenge/card/january-leetcoding-challenge-2021/579/week-1-january-1st-january-7th/3595/) | [cpp](./07.%20Longest%20Substring%20Without%20Repeating%20Characters.cpp) |
12+
| .8 | [Check If Two String Arrays are Equivalent](https://leetcode.com/explore/challenge/card/january-leetcoding-challenge-2021/580/week-2-january-8th-january-14th/3597/) | [cpp](./08.%20Check%20If%20Two%20String%20Arrays%20are%20Equivalent.cpp) |
13+
| . | []() | [cpp](./.%20.cpp) |
1214
| . | []() | [cpp](./.%20.cpp) |
1315
| . | []() | [cpp](./.%20.cpp) |

0 commit comments

Comments
 (0)