Skip to content

Commit 1b779bf

Browse files
refactor 161
1 parent a9c5c8e commit 1b779bf

File tree

1 file changed

+2
-29
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+2
-29
lines changed

src/main/java/com/fishercoder/solutions/_161.java

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,5 @@
11
package com.fishercoder.solutions;
22

3-
/**
4-
* 161. One Edit Distance
5-
*
6-
* Given two strings s and t, determine if they are both one edit distance apart.
7-
*
8-
* Note:
9-
* There are 3 possiblities to satisify one edit distance apart:
10-
* Insert a character into s to get t
11-
* Delete a character from s to get t
12-
* Replace a character of s to get t
13-
*
14-
* Example 1:
15-
* Input: s = "ab", t = "acb"
16-
* Output: true
17-
* Explanation: We can insert 'c' into s to get t.
18-
*
19-
* Example 2:
20-
* Input: s = "cab", t = "ad"
21-
* Output: false
22-
* Explanation: We cannot get t from s by only one step.
23-
*
24-
* Example 3:
25-
* Input: s = "1203", t = "1213"
26-
* Output: true
27-
* Explanation: We can replace '0' with '1' to get t.
28-
*/
293
public class _161 {
304
public static class Solution1 {
315
public boolean isOneEditDistance(String s, String t) {
@@ -48,9 +22,8 @@ public boolean isOneEditDistance(String s, String t) {
4822
j++;
4923
}
5024
}
51-
return diffCnt == 1
52-
|| diffCnt
53-
== 0;//it could be the last char of the longer is the different one, in that case, diffCnt remains to be zero
25+
return diffCnt == 1 || diffCnt == 0;
26+
//it could be the last char of the longer is the different one, in that case, diffCnt remains to be zero
5427
} else if (s.length() == t.length()) {
5528
int diffCnt = 0;
5629
for (int i = 0; i < s.length(); i++) {

0 commit comments

Comments
 (0)