Skip to content

Commit ab20d20

Browse files
committed
[Swift 4.2] Update README.md for Karatsuba multiplication
1 parent 86d6cd1 commit ab20d20

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

Karatsuba Multiplication/README.markdown

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,15 @@ Here's the full implementation. Note that the recursive algorithm is most effici
7171

7272
```swift
7373
// Karatsuba Multiplication
74-
func karatsuba(_ num1: Int, by num2: Int) -> Int {
75-
let num1Array = String(num1).characters
76-
let num2Array = String(num2).characters
74+
func karatsuba(_ num1: Int, by num2: Int) -> Int {
75+
let num1String = String(num1)
76+
let num2String = String(num2)
7777

78-
guard num1Array.count > 1 && num2Array.count > 1 else {
79-
return num1*num2
78+
guard num1String.count > 1 && num2String.count > 1 else {
79+
return multiply(num1, by: num2)
8080
}
8181

82-
let n = max(num1Array.count, num2Array.count)
82+
let n = max(num1String.count, num2String.count)
8383
let nBy2 = n / 2
8484

8585
let a = num1 / 10^^nBy2

0 commit comments

Comments
 (0)