Leetcode Problem 1662. Check If Two String Arrays are Equivalent

1662. Check If Two String Arrays are Equivalent

Leetcode Solutions

Two Pointers Approach

  1. Initialize word1Pointer and word2Pointer to 0. These pointers will point to the current string in the arrays word1 and word2 respectively.
  2. Initialize char1Pointer and char2Pointer to 0. These pointers will point to the current characters in the strings referenced by word1Pointer and word2Pointer.
  3. While word1Pointer and word2Pointer have not reached the end of their respective arrays: a. Compare the characters at char1Pointer and char2Pointer. b. If they are not equal, return false. c. Increment char1Pointer and char2Pointer. d. If char1Pointer has reached the end of its string, move word1Pointer to the next string and reset char1Pointer. e. If char2Pointer has reached the end of its string, move word2Pointer to the next string and reset char2Pointer.
  4. If both pointers have reached the end of their arrays, return true. Otherwise, if one pointer has more strings to traverse, return false.
UML Thumbnail

Concatenate and Compare Approach

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...