Leetcode Problem 1813. Sentence Similarity III

1813. Sentence Similarity III

Leetcode Solutions

Two Pointer Comparison

  1. Split both sentences into arrays of words.
  2. Initialize two pointers, i and j, to the start of each word array.
  3. While i is less than the length of the first sentence and j is less than the length of the second sentence, and the words at i and j are equal, increment both i and j.
  4. Set i and j to point to the end of their respective word arrays.
  5. While i and j are greater than or equal to 0, and the words at i and j are equal, decrement both i and j.
  6. If either i or j is less than 0, return true as the sentences are similar.
  7. Otherwise, return false.
UML Thumbnail

Deque-based Comparison

Ask Question

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

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...