-
[LeetCode] 1662. Check If Two String Arrays are EquivalentLeetCode 2023. 12. 1. 17:05728x90
https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent
Check If Two String Arrays are Equivalent - LeetCode
Can you solve this real interview question? 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
leetcode.com
1662. Check If Two String Arrays are Equivalent - Easy


String 이 주어진 두 Array가 있다.
각각의 Array의 string을 쭉 이어붙였을때, 두 String이 같은지 판별하는 문제다.
각각의 Array에서 string을 +한 다음, strcmp를 해도 되지만,
두 포인터를 각각의 Array에 두고 하나하나 비교하는 방법으로 진행했다.
class Solution { public: bool arrayStringsAreEqual(vector<string>& word1, vector<string>& word2) { int i=0, j=0, k=0, l=0; while (i < word1.size() && j < word2.size()) { if (word1[i][k] != word2[j][l]) return false; if (++k == word1[i].size()) k=0, i++; if (++l == word2[j].size()) l=0, j++; } return i==word1.size() && j==word2.size(); } };'LeetCode' 카테고리의 다른 글
[LeetCode] 606.Construct String from Binary Tree (1) 2023.12.08 [LeetCode] 1611. Minimum One Bit Operations to Make Integers Zero (1) 2023.11.30 [LeetCode] 695. Max Area of Island (2) 2023.11.29 [LeetCode] 2147. Number of Ways to Divide a long Corridor (1) 2023.11.28 [LeetCode] 557. Reverse Words in a String III (0) 2023.11.27