First try failed at the test case
["fff", "ffff"] and ["avc", ""]
func numDistinct(_ s: String, _ t: String) -> Int {
if t.count == 0 {
return 1
}
if s.count < t.count {
return 0
}
let S = Array(s)
let T = Array(t)
var tmp = Array(repeating: 1, count: S.count + 1)
var dp = [Int]()
for i in 1...T.count {
dp = Array(repeating: 0, count: S.count + 1)
for j in i...S.count {
if S[j-1] == T[i-1] {
dp[j] = dp[j-1] + tmp[j-1]
} else {
dp[j] = dp[j-1]
}
}
tmp = dp
}
return dp[S.count]
}