@@ -223,6 +223,48 @@ impl Solution {
223
223
}
224
224
```
225
225
226
+ ``` swift
227
+ class Solution {
228
+ func oneEditAway (_ first : String , _ second : String ) -> Bool {
229
+ let m = first.count , n = second.count
230
+ if m < n {
231
+ return oneEditAway (second, first)
232
+ }
233
+ if m - n > 1 {
234
+ return false
235
+ }
236
+
237
+ var cnt = 0
238
+ var firstIndex = first.startIndex
239
+ var secondIndex = second.startIndex
240
+
241
+ if m == n {
242
+ while secondIndex != second.endIndex {
243
+ if first[firstIndex] != second[secondIndex] {
244
+ cnt += 1
245
+ if cnt > 1 {
246
+ return false
247
+ }
248
+ }
249
+ firstIndex = first.index (after : firstIndex)
250
+ secondIndex = second.index (after : secondIndex)
251
+ }
252
+ return true
253
+ } else {
254
+ while firstIndex != first.endIndex {
255
+ if secondIndex == second.endIndex || (secondIndex != second.endIndex && first[firstIndex] != second[secondIndex]) {
256
+ cnt += 1
257
+ } else {
258
+ secondIndex = second.index (after : secondIndex)
259
+ }
260
+ firstIndex = first.index (after : firstIndex)
261
+ }
262
+ }
263
+ return cnt < 2
264
+ }
265
+ }
266
+ ```
267
+
226
268
<!-- tabs: end -->
227
269
228
270
<!-- end -->
0 commit comments