Skip to content

Commit ac6e627

Browse files
add 2506
1 parent 670ad05 commit ac6e627

File tree

2 files changed

+36
-0
lines changed
  • paginated_contents/algorithms/3rd_thousand
  • src/main/java/com/fishercoder/solutions/thirdthousand

2 files changed

+36
-0
lines changed

paginated_contents/algorithms/3rd_thousand/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
| 2525 | [Categorize Box According to Criteria](https://leetcode.com/problems/categorize-box-according-to-criteria/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2525.java) | [:tv:](https://youtu.be/dIciftyQXHo) | Easy ||
3333
| 2520 | [Count the Digits That Divide a Number](https://leetcode.com/problems/count-the-digits-that-divide-a-number/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2520.java) | [:tv:](https://youtu.be/7SHHsS5kPJ8) | Easy ||
3434
| 2515 | [Shortest Distance to Target String in a Circular Array](https://leetcode.com/problems/shortest-distance-to-target-string-in-a-circular-array/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2515.java) || Easy ||
35+
| 2506 | [Count Pairs Of Similar Strings](https://leetcode.com/problems/count-pairs-of-similar-strings/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2506.java) || Easy ||
3536
| 2496 | [Maximum Value of a String in an Array](https://leetcode.com/problems/maximum-value-of-a-string-in-an-array/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2496.java) || Easy ||
3637
| 2492 | [Minimum Score of a Path Between Two Cities](https://leetcode.com/problems/minimum-score-of-a-path-between-two-cities/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2492.java) || Medium | Union Find
3738
| 2485 | [Find the Pivot Integer](https://leetcode.com/problems/find-the-pivot-integer/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/thirdthousand/_2485.java) || Easy ||
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.fishercoder.solutions.thirdthousand;
2+
3+
public class _2506 {
4+
public static class Solution1 {
5+
public int similarPairs(String[] words) {
6+
String[] symbols = new String[words.length];
7+
for (int i = 0; i < words.length; i++) {
8+
symbols[i] = compress(words[i]);
9+
}
10+
int pairs = 0;
11+
for (int i = 0; i < symbols.length - 1; i++) {
12+
for (int j = i + 1; j < symbols.length; j++) {
13+
if (symbols[i].equals(symbols[j])) {
14+
pairs++;
15+
}
16+
}
17+
}
18+
return pairs;
19+
}
20+
21+
private String compress(String word) {
22+
int[] count = new int[26];
23+
for (char c : word.toCharArray()) {
24+
count[c - 'a']++;
25+
}
26+
StringBuilder sb = new StringBuilder();
27+
for (int i = 0; i < 26; i++) {
28+
if (count[i] > 0) {
29+
sb.append(i + 'a');
30+
}
31+
}
32+
return sb.toString();
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)