Given two arrays of strings sentence1 and sentence2, and an array of string pairs similarPairs where similarPairs[i] = [x_i, y_i] represents that the words x_i and y_i are similar, determine if sentence1 and sentence2 are similar.
Two sentences are similar if:
They have the same length.
For each index i, the word sentence1[i] is similar to sentence2[i].
Two words w1 and w2 are similar if:
w1 == w2, or
The pair [w1, w2] or [w2, w1] exists in similarPairs.
Return true if sentence1 and sentence2 are similar, and false otherwise.
Note: The similarity relation is not transitive. If
w1is similar tow2andw2is similar tow3, it does not imply thatw1andw3are similar.
Constraints:
sentence1.length, sentence2.length
sentence1[i].length, sentence2[i].length
sentence1[i] and sentence2[i] consist of English letters.
similarPairs.length
similarPairs[i].length
x_i.length, y_i.length
x_i and y_i consist of lowercase and uppercase English letters.
All the pairs (x_i, y_i) are distinct.
Given two arrays of strings sentence1 and sentence2, and an array of string pairs similarPairs where similarPairs[i] = [x_i, y_i] represents that the words x_i and y_i are similar, determine if sentence1 and sentence2 are similar.
Two sentences are similar if:
They have the same length.
For each index i, the word sentence1[i] is similar to sentence2[i].
Two words w1 and w2 are similar if:
w1 == w2, or
The pair [w1, w2] or [w2, w1] exists in similarPairs.
Return true if sentence1 and sentence2 are similar, and false otherwise.
Note: The similarity relation is not transitive. If
w1is similar tow2andw2is similar tow3, it does not imply thatw1andw3are similar.
Constraints:
sentence1.length, sentence2.length
sentence1[i].length, sentence2[i].length
sentence1[i] and sentence2[i] consist of English letters.
similarPairs.length
similarPairs[i].length
x_i.length, y_i.length
x_i and y_i consist of lowercase and uppercase English letters.
All the pairs (x_i, y_i) are distinct.