diff --git a/lcci/17.18.Shortest Supersequence/README.md b/lcci/17.18.Shortest Supersequence/README.md index 60e46bd5b94c6..875bcfe96467c 100644 --- a/lcci/17.18.Shortest Supersequence/README.md +++ b/lcci/17.18.Shortest Supersequence/README.md @@ -187,6 +187,50 @@ function shortestSeq(big: number[], small: number[]): number[] { } ``` +```swift +class Solution { + func shortestSeq(_ big: [Int], _ small: [Int]) -> [Int] { + let needCount = small.count + var need = [Int: Int]() + var window = [Int: Int]() + small.forEach { need[$0, default: 0] += 1 } + + var count = needCount + var minLength = Int.max + var result = (-1, -1) + + var left = 0 + for right in 0.. diff --git a/lcci/17.18.Shortest Supersequence/README_EN.md b/lcci/17.18.Shortest Supersequence/README_EN.md index 9a5847f4fba9e..a9abfa2daeb60 100644 --- a/lcci/17.18.Shortest Supersequence/README_EN.md +++ b/lcci/17.18.Shortest Supersequence/README_EN.md @@ -191,6 +191,50 @@ function shortestSeq(big: number[], small: number[]): number[] { } ``` +```swift +class Solution { + func shortestSeq(_ big: [Int], _ small: [Int]) -> [Int] { + let needCount = small.count + var need = [Int: Int]() + var window = [Int: Int]() + small.forEach { need[$0, default: 0] += 1 } + + var count = needCount + var minLength = Int.max + var result = (-1, -1) + + var left = 0 + for right in 0.. diff --git a/lcci/17.18.Shortest Supersequence/Solution.swift b/lcci/17.18.Shortest Supersequence/Solution.swift new file mode 100644 index 0000000000000..7fc3c68e7088e --- /dev/null +++ b/lcci/17.18.Shortest Supersequence/Solution.swift @@ -0,0 +1,41 @@ +class Solution { + func shortestSeq(_ big: [Int], _ small: [Int]) -> [Int] { + let needCount = small.count + var need = [Int: Int]() + var window = [Int: Int]() + small.forEach { need[$0, default: 0] += 1 } + + var count = needCount + var minLength = Int.max + var result = (-1, -1) + + var left = 0 + for right in 0..