Skip to content

Instantly share code, notes, and snippets.

@congnd
Created February 21, 2020 00:19
Show Gist options
  • Select an option

  • Save congnd/c60a5b8d45bed18e2412c2d68f415c50 to your computer and use it in GitHub Desktop.

Select an option

Save congnd/c60a5b8d45bed18e2412c2d68f415c50 to your computer and use it in GitHub Desktop.
Swift solution for is-subsequence challenge: https://leetcode.com/problems/is-subsequence
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