Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit32bd02c

Browse files
add 1657
1 parent977b69c commit32bd02c

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1657|[Determine if Two Strings Are Close](https://leetcode.com/problems/determine-if-two-strings-are-close/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1657.java)||Medium|Greedy|
1112
|1656|[Design an Ordered Stream](https://leetcode.com/problems/design-an-ordered-stream/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1656.java)||Easy|Array, Design|
1213
|1652|[Defuse the Bomb](https://leetcode.com/problems/defuse-the-bomb/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1652.java)||Easy|Array|
1314
|1640|[Check Array Formation Through Concatenation](https://leetcode.com/problems/check-array-formation-through-concatenation/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1640.java)||Easy|Array, Sort|
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
packagecom.fishercoder.solutions;
2+
3+
importjava.util.Arrays;
4+
importjava.util.HashSet;
5+
importjava.util.Set;
6+
7+
publicclass_1657 {
8+
publicstaticclassSolution1 {
9+
publicbooleancloseStrings(Stringword1,Stringword2) {
10+
int[]counts1 =newint[26];
11+
int[]counts2 =newint[26];
12+
Set<Character>set1 =newHashSet<>();
13+
Set<Character>set2 =newHashSet<>();
14+
for (charc :word1.toCharArray()) {
15+
counts1[c -'a']++;
16+
set1.add(c);
17+
}
18+
Arrays.sort(counts1);
19+
for (charc :word2.toCharArray()) {
20+
counts2[c -'a']++;
21+
set2.add(c);
22+
}
23+
Arrays.sort(counts2);
24+
returnset1.equals(set2) &&Arrays.equals(counts1,counts2);
25+
}
26+
27+
}
28+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
packagecom.fishercoder;
2+
3+
importcom.fishercoder.solutions._1657;
4+
importorg.junit.BeforeClass;
5+
importorg.junit.Test;
6+
7+
importstaticorg.junit.Assert.assertEquals;
8+
9+
publicclass_1657Test {
10+
privatestatic_1657.Solution1solution1;
11+
12+
@BeforeClass
13+
publicstaticvoidsetup() {
14+
solution1 =new_1657.Solution1();
15+
}
16+
17+
@Test
18+
publicvoidtest1() {
19+
assertEquals(true,solution1.closeStrings("abc","bca"));
20+
}
21+
22+
@Test
23+
publicvoidtest2() {
24+
assertEquals(false,solution1.closeStrings("a","aa"));
25+
}
26+
27+
@Test
28+
publicvoidtest3() {
29+
assertEquals(true,solution1.closeStrings("cabbba","abbccc"));
30+
}
31+
32+
@Test
33+
publicvoidtest4() {
34+
assertEquals(false,solution1.closeStrings("cabbba","aabbss"));
35+
}
36+
37+
@Test
38+
publicvoidtest5() {
39+
assertEquals(false,solution1.closeStrings("abbbzcf","babzzcz"));
40+
}
41+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp