1- // last checked with Xcode 9.0b4
1+ // last checked with Xcode 11.4
22#if swift(>=4.0)
33print ( " Hello, Swift 4! " )
44#endif
@@ -7,10 +7,10 @@ extension String {
77 public func longestCommonSubsequence( _ other: String ) -> String {
88
99 func lcsLength( _ other: String ) -> [ [ Int ] ] {
10- var matrix = [ [ Int] ] ( repeating: [ Int] ( repeating: 0 , count: other. characters . count+ 1 ) , count: self . characters . count+ 1 )
10+ var matrix = [ [ Int] ] ( repeating: [ Int] ( repeating: 0 , count: other. count+ 1 ) , count: self . count+ 1 )
1111
12- for (i, selfChar) in self . characters . enumerated ( ) {
13- for (j, otherChar) in other. characters . enumerated ( ) {
12+ for (i, selfChar) in self . enumerated ( ) {
13+ for (j, otherChar) in other. enumerated ( ) {
1414 if otherChar == selfChar {
1515 matrix [ i+ 1 ] [ j+ 1 ] = matrix [ i] [ j] + 1
1616 } else {
@@ -22,8 +22,8 @@ extension String {
2222 }
2323
2424 func backtrack( _ matrix: [ [ Int ] ] ) -> String {
25- var i = self . characters . count
26- var j = other. characters . count
25+ var i = self . count
26+ var j = other. count
2727 var charInSequence = self . endIndex
2828
2929 var lcs = String ( )
@@ -41,7 +41,7 @@ extension String {
4141 lcs. append ( self [ charInSequence] )
4242 }
4343 }
44- return String ( lcs. characters . reversed ( ) )
44+ return String ( lcs. reversed ( ) )
4545 }
4646
4747 return backtrack ( lcsLength ( other) )
0 commit comments