Created
February 21, 2020 00:19
-
-
Save congnd/c60a5b8d45bed18e2412c2d68f415c50 to your computer and use it in GitHub Desktop.
Swift solution for is-subsequence challenge: https://leetcode.com/problems/is-subsequence
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
| class Solution { | |
| func isSubsequence(_ s: String, _ t: String) -> Bool { | |
| let sub = Array(s.utf8) | |
| let string = Array(t.utf8) | |
| var subIndex: Int = 0 | |
| var stringIndex: Int = 0 | |
| while stringIndex < string.count, subIndex < sub.count { | |
| if string[stringIndex] == sub[subIndex] { | |
| subIndex += 1 | |
| } | |
| stringIndex += 1 | |
| } | |
| return subIndex == sub.count | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment