- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_1790.java
28 lines (26 loc) · 862 Bytes
/
_1790.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
packagecom.fishercoder.solutions.secondthousand;
publicclass_1790 {
publicstaticclassSolution1 {
publicbooleanareAlmostEqual(Strings1, Strings2) {
if (s1.equals(s2)) {
returntrue;
}
for (inti = 0; i < s1.length(); i++) {
for (intj = 0; j < i; j++) {
StringnewS1 = swap(s1, i, j);
if (newS1.equals(s2)) {
returntrue;
}
}
}
returnfalse;
}
privateStringswap(Stringstr, inti, intj) {
charc = str.charAt(i);
StringBuildersb = newStringBuilder(str);
sb.replace(i, i + 1, str.charAt(j) + "");
sb.replace(j, j + 1, "" + c);
returnsb.toString();
}
}
}