You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Longest Common Subsequence/README.markdown
+15-16
Original file line number
Diff line number
Diff line change
@@ -18,9 +18,9 @@ To determine the length of the LCS between all combinations of substrings of `a`
18
18
19
19
> **Note:** During the following explanation, `n` is the length of string `a`, and `m` is the length of string `b`.
20
20
21
-
To find the lengths of all possible subsequences, we use a helper function, `lcsLength()`. This creates a matrix of size `(n+1)` by `(m+1)`, where `matrix[x][y]` is the length of the LCS between the substrings `a[0...x-1]` and `b[0...y-1]`.
21
+
To find the lengths of all possible subsequences, we use a helper function, `lcsLength(_:)`. This creates a matrix of size `(n+1)` by `(m+1)`, where `matrix[x][y]` is the length of the LCS between the substrings `a[0...x-1]` and `b[0...y-1]`.
22
22
23
-
Given strings `"ABCBX"` and `"ABDCAB"`, the output matrix of `lcsLength()` is the following:
23
+
Given strings `"ABCBX"` and `"ABDCAB"`, the output matrix of `lcsLength(_:)` is the following:
24
24
25
25
```
26
26
| | Ø | A | B | D | C | A | B |
@@ -34,16 +34,15 @@ Given strings `"ABCBX"` and `"ABDCAB"`, the output matrix of `lcsLength()` is th
34
34
35
35
In this example, if we look at `matrix[3][4]` we find the value `3`. This means the length of the LCS between `a[0...2]` and `b[0...3]`, or between `"ABC"` and `"ABDC"`, is 3. That is correct, because these two substrings have the subsequence `ABC` in common. (Note: the first row and column of the matrix are always filled with zeros.)
36
36
37
-
Here is the source code for `lcsLength()`; this lives in an extension on `String`:
37
+
Here is the source code for `lcsLength(_:)`; this lives in an extension on `String`:
38
38
39
39
```swift
40
-
funclcsLength(other: String) -> [[Int]] {
40
+
funclcsLength(_other: String) -> [[Int]] {
41
41
42
-
var matrix = [[Int]](count: self.characters.count+1,
0 commit comments