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

Commit4ee26dc

Browse files
add 1790
1 parent8154859 commit4ee26dc

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ _If you like this project, please leave me a star._ ★
99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
1111
|1791|[Find Center of Star Graph](https://leetcode.com/problems/find-center-of-star-graph/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1791.java)||Medium|Graph|
12+
|1790|[Check if One String Swap Can Make Strings Equal](https://leetcode.com/problems/check-if-one-string-swap-can-make-strings-equal/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1790.java)||Easy|String|
1213
|1785|[Minimum Elements to Add to Form a Given Sum](https://leetcode.com/problems/minimum-elements-to-add-to-form-a-given-sum/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1785.java)||Medium|Greedy|
1314
|1784|[Check if Binary String Has at Most One Segment of Ones](https://leetcode.com/problems/check-if-binary-string-has-at-most-one-segment-of-ones/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1784.java)||Easy|Greedy|
1415
|1781|[Sum of Beauty of All Substrings](https://leetcode.com/problems/sum-of-beauty-of-all-substrings/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1781.java)||Medium|HashTable, String|
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
packagecom.fishercoder.solutions;
2+
3+
publicclass_1790 {
4+
publicstaticclassSolution1 {
5+
publicbooleanareAlmostEqual(Strings1,Strings2) {
6+
if (s1.equals(s2)) {
7+
returntrue;
8+
}
9+
for (inti =0;i <s1.length();i++) {
10+
for (intj =0;j <i;j++) {
11+
StringnewS1 =swap(s1,i,j);
12+
if (newS1.equals(s2)) {
13+
returntrue;
14+
}
15+
}
16+
}
17+
returnfalse;
18+
}
19+
20+
privateStringswap(Stringstr,inti,intj) {
21+
charc =str.charAt(i);
22+
StringBuildersb =newStringBuilder(str);
23+
sb.replace(i,i +1,str.charAt(j) +"");
24+
sb.replace(j,j +1,"" +c);
25+
returnsb.toString();
26+
}
27+
}
28+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
packagecom.fishercoder;
2+
3+
importcom.fishercoder.solutions._1790;
4+
importorg.junit.BeforeClass;
5+
importorg.junit.Test;
6+
7+
importstaticorg.junit.Assert.assertEquals;
8+
9+
publicclass_1790Test {
10+
privatestatic_1790.Solution1solution1;
11+
12+
@BeforeClass
13+
publicstaticvoidsetup() {
14+
solution1 =new_1790.Solution1();
15+
}
16+
17+
@Test
18+
publicvoidtest1() {
19+
assertEquals(false,solution1.areAlmostEqual("a","z"));
20+
}
21+
22+
@Test
23+
publicvoidtest2() {
24+
assertEquals(true,solution1.areAlmostEqual("bank","kanb"));
25+
}
26+
27+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp