-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution161.java
More file actions
executable file
·30 lines (30 loc) · 925 Bytes
/
Copy pathSolution161.java
File metadata and controls
executable file
·30 lines (30 loc) · 925 Bytes
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
29
30
class Solution161 {
public boolean isOneEditDistance(String s, String t) {
if (Math.abs(s.length() - t.length()) > 1) return false;
int sp = 0, tp = 0;
boolean flag = false;
while (sp < s.length() && tp < t.length()) {
if (s.charAt(sp) == t.charAt(tp)) {
sp++;
tp++;
}
else {
if (flag) return false;
else {
flag = true;
if (s.length() == t.length()) {
sp++;
tp++;
}
else if (s.length() < t.length()) {
tp++;
}
else {
sp++;
}
}
}
}
return (s.length() == t.length() && flag) || s.length() != t.length();
}
}