We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent eb0f268 commit 6a15c62Copy full SHA for 6a15c62
Strings/one_edit.go
@@ -0,0 +1,34 @@
1
+package main
2
+
3
+func OneEdit(stringOne string, stringTwo string) bool {
4
+ lengthOne := len(stringOne)
5
+ lengthTwo := len(stringTwo)
6
+ if abs(lengthOne-lengthTwo) > 1 {
7
+ return false
8
+ }
9
+ for i := 0; i < min(lengthOne, lengthTwo); i++ {
10
+ if stringOne[i] != stringTwo[i] {
11
+ if lengthOne > lengthTwo {
12
+ return stringOne[i+1:] == stringTwo[i:]
13
+ } else if lengthTwo > lengthOne {
14
+ return stringTwo[i+1:] == stringOne[i:]
15
+ } else {
16
+ return stringOne[i+1:] == stringTwo[i+1:]
17
18
19
20
+ return true
21
+}
22
23
+func abs(a int) int {
24
+ if a < 0 {
25
+ return -a
26
27
+ return a
28
29
+func min(a, b int) int {
30
+ if a < b {
31
32
33
+ return b
34
0 commit comments