Class Solution
-
- All Implemented Interfaces:
public final class Solution2506 - Count Pairs Of Similar Strings.
Easy
You are given a 0-indexed string array
words.Two strings are similar if they consist of the same characters.
For example,
"abca"and"cba"are similar since both consist of characters'a','b', and'c'.However,
"abacba"and"bcfd"are not similar since they do not consist of the same characters.
Return the number of pairs
(i, j)such that0 <= i < j <= word.length - 1and the two stringswords[i]andwords[j]are similar.Example 1:
Input: words = "aba","aabb","abcd","bac","aabc"
Output: 2
Explanation: There are 2 pairs that satisfy the conditions:
i = 0 and j = 1 : both words0 and words1 only consist of characters 'a' and 'b'.
i = 3 and j = 4 : both words3 and words4 only consist of characters 'a', 'b', and 'c'.
Example 2:
Input: words = "aabb","ab","ba"
Output: 3
Explanation: There are 3 pairs that satisfy the conditions:
i = 0 and j = 1 : both words0 and words1 only consist of characters 'a' and 'b'.
i = 0 and j = 2 : both words0 and words2 only consist of characters 'a' and 'b'.
i = 1 and j = 2 : both words1 and words2 only consist of characters 'a' and 'b'.
Example 3:
Input: words = "nba","cba","dba"
Output: 0
Explanation: Since there does not exist any pair that satisfies the conditions, we return 0.
Constraints:
1 <= words.length <= 1001 <= words[i].length <= 100words[i]consist of only lowercase English letters.
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final IntegersimilarPairs(Array<String> words)-
-
Method Detail
-
similarPairs
final Integer similarPairs(Array<String> words)
-
-
-
-