We can represent a sentence as an array of words. For example, the sentence "I am happy with leetcode" can be represented as arr = ["I","am","happy","with","leetcode"].
Given two sentences sentence1 and sentence2 each represented as a string array and given an array of string pairs similarPairs where similarPairs[i] = [xi, yi] indicates that the two words xi and yi are similar.
Return true if sentence1 and sentence2 are similar, or false if they are not similar.
Two sentences are similar if:
- They have the same length (i.e., the same number of words)
sentence1[i]andsentence2[i]are similar for alli
Note: A word is always similar to itself. The similarity relation is not transitive. For example, if words a and b are similar, and words b and c are similar, a and c are not necessarily similar.
Input & Output
Constraints
- 1 ≤ sentence1.length, sentence2.length ≤ 1000
- 1 ≤ sentence1[i].length, sentence2[i].length ≤ 20
- 0 ≤ similarPairs.length ≤ 1000
- similarPairs[i].length == 2