Last active
October 16, 2021 00:40
-
-
Save germanescobar/1edc6cbac6ce3b6d5dead781c81aef32 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var isInterleave = function(s1, s2, s3) { | |
// caso trivial | |
if (s3.length === 0) { | |
return s1.length === 0 && s2.length === 0 | |
} | |
// caso general | |
let result1 = false, result2 = false | |
if (s1.length > 0 && s3[0] === s1[0]) { | |
result1 = isInterleave(s1.substring(1), s2, s3.substring(1)) | |
} | |
if (s2.length > 0 && s3[0] === s2[0]) { | |
result2 = isInterleave(s1, s2.substring(1), s3.substring(1)) | |
} | |
return result1 || result2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment