Skip to content

Commit 16e6f32

Browse files
committed
Minor fix
1 parent cfa8784 commit 16e6f32

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/main/java/com/ctci/arraysandstrings/OneAway.java

+3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ private static boolean checkForMaxOneInsertOrDeleteInS1(String s1, String s2) {
4242
int j = 0;
4343
int s1Len = s1.length();
4444
int s2Len = s2.length();
45+
if (Math.abs(s1Len - s2Len) > 1) return false;
46+
4547
while (i < s1Len && j < s2Len) {
4648
if (s1.charAt(i) != s2.charAt(j)) {
4749
if (s1Len > s2Len) {
@@ -63,5 +65,6 @@ public static void main(String[] args) {
6365
System.out.println("pale, bale: " + isOneEditAway("pale", "bale"));
6466
System.out.println("pale, bake: " + isOneEditAway("pale", "bake"));
6567
System.out.println("ram, rama: " + isOneEditAway("ram", "rama"));
68+
System.out.println("ram, ramaaaaaaa: " + isOneEditAway("ram", "ramaaaaaaa"));
6669
}
6770
}

0 commit comments

Comments
 (0)