https://leetcode.com/problems/interleaving-string/

`Input: s1 = "aabcc", s2 = "dbbca", s3 = "aadbbcbcac"` 我们将s1分解成`aa, bc, c`然后将s2分解成`dbbc, a`。依靠`aa+dbbc+bc+a+c`就能组合成s3，而Example2不行，返回False。

``````class Solution {
func isInterleave(_ s1: String, _ s2: String, _ s3: String) -> Bool {
guard s1.count + s2.count == s3.count else { return false }
var dp = Array<Bool>(repeating: false, count: s2.count + 1)
for i in 0...s1.count {
for j in 0...s2.count {
if i == 0 && j == 0 {
dp[j] = true
} else if i == 0 {
dp[j] = dp[j - 1] && s2[j - 1] == s3[i + j - 1]
} else if j == 0 {
dp[j] = dp[j] && s1[i - 1] == s3[i + j - 1]
} else {
dp[j] = (dp[j] && s1[i - 1] == s3[i + j - 1]) || (dp[j - 1] && s2[j - 1] == s3[i + j - 1])
}
}
}
return dp[s2.count]
}
}

extension String {
subscript(_ i: Int) -> Character {
return self[self.index(self.startIndex, offsetBy: i)]
}
}
``````

Runtime: 16 ms, faster than 91.67% of Swift online submissions for Interleaving String.
Memory Usage: 18.8 MB, less than 100.00% of Swift online submissions for Interleaving String.