File tree Expand file tree Collapse file tree 1 file changed +3
-3
lines changed
Rabin-Karp/Rabin-Karp.playground Expand file tree Collapse file tree 1 file changed +3
-3
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ print("Hello, Swift 4!")
8
8
import UIKit
9
9
10
10
struct Constants {
11
- static let hashMultiplier = 69069
11
+ static let hashMultiplier = 69061
12
12
}
13
13
14
14
precedencegroup PowerPrecedence { higherThan : MultiplicationPrecedence }
@@ -30,8 +30,8 @@ extension Character {
30
30
// Find first position of pattern in the text using Rabin Karp algorithm
31
31
public func search( text: String , pattern: String ) -> Int {
32
32
// convert to array of ints
33
- let patternArray = pattern. flatMap { $0. asInt }
34
- let textArray = text. flatMap { $0. asInt }
33
+ let patternArray = pattern. compactMap { $0. asInt }
34
+ let textArray = text. compactMap { $0. asInt }
35
35
36
36
if textArray. count < patternArray. count {
37
37
return - 1
You can’t perform that action at this time.
0 commit comments