[go: nahoru, domu]

Skip to content

Commit

Permalink
Submit 392. Is Subsequence
Browse files Browse the repository at this point in the history
  • Loading branch information
Binlogo committed Jul 27, 2020
1 parent 0abf877 commit 5b521cb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//: [Previous](@previous)

import Foundation

class Solution {
func isSubsequence(_ s: String, _ t: String) -> Bool {
let sChars = [Character](s), tChars = [Character](t)
let n = sChars.count, m = tChars.count
var i = 0, j = 0
while i < n && j < m {
if sChars[i] == tChars[j] {
i += 1
}
j += 1
}
return i == n
}
}

// Tests
let s = Solution()
s.isSubsequence("abc", "ahbgdc") == true
s.isSubsequence("axc", "ahbgdc") == false

//: [Next](@next)
2 changes: 2 additions & 0 deletions LeetCodePlayground.playground/contents.xcplayground
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,7 @@
<page name='95_UniqueBinarySearchTreesII'/>
<page name='剑指 Offer 11. 旋转数组的最小数字'/>
<page name='64_MinimumPathSum'/>
<page name='1025_DivisorGame'/>
<page name='392_IsSubsequence'/>
</pages>
</playground>

0 comments on commit 5b521cb

Please sign in to comment.