반응형
https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/description
word1과 word2의 문자를 하나씩 탐색하며 비교해줍니다.
class Solution {
public:
bool arrayStringsAreEqual(vector<string>& word1, vector<string>& word2) {
int i=0, ii=0, j=0, jj=0;
while(i < word1.size() && j < word2.size()) {
if(word1[i][ii] != word2[j][jj]) {
return false;
}
ii++, jj++;
if(ii == word1[i].size()) {
ii = 0;
i++;
}
if(jj == word2[j].size()) {
jj = 0;
j++;
}
}
return i == word1.size() && j == word2.size();
}
};
반응형
'Algorithm' 카테고리의 다른 글
LeetCode 1266. Minimum Time Visiting All Points (1) | 2023.12.03 |
---|---|
LeetCode 1160. Find Words That Can Be Formed by Characters (2) | 2023.12.02 |
LeetCode 2147. Number of Ways to Divide a Long Corridor (1) | 2023.11.29 |
LeetCode 935. Knight Dialer (1) | 2023.11.29 |
LeetCode 1561. Maximum Number of Coins You Can Get (0) | 2023.11.24 |