11package 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- */
293public class _161 {
304public static class Solution1 {
315public boolean isOneEditDistance (String s ,String t ) {
@@ -48,9 +22,8 @@ public boolean isOneEditDistance(String s, String t) {
4822j ++;
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 ()) {
5528int diffCnt =0 ;
5629for (int i =0 ;i <s .length ();i ++) {