kt: add «392. Is Subsequence»
URL: https://leetcode.com/problems/is-subsequence/ Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
parent
589ae3bcea
commit
17451369aa
1 changed files with 20 additions and 0 deletions
20
kt/is-subsequence.kt
Normal file
20
kt/is-subsequence.kt
Normal file
|
@ -0,0 +1,20 @@
|
|||
class Solution {
|
||||
fun isSubsequence(
|
||||
s: String,
|
||||
t: String,
|
||||
): Boolean {
|
||||
var i = 0
|
||||
|
||||
for (j in t.indices) {
|
||||
if (i < s.length && t[j] == s[i]) {
|
||||
i++
|
||||
}
|
||||
|
||||
if (i >= s.length) {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return i == s.length
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue