Skip to content

Commit 10eb580

Browse files
committed
392. Is Subsequence
1 parent 6de342c commit 10eb580

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

is-subsequence.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//Runtime: 67 ms
2+
class Solution {
3+
public:
4+
int look(char c, string &t, int idx) {
5+
for (int i = idx; i < t.size(); i++) {
6+
if (t[i] == c) {
7+
return i;
8+
}
9+
}
10+
return -1;
11+
}
12+
13+
bool isSubsequence(string s, string t) {
14+
int idx = -1;
15+
for (char c : s) {
16+
idx = look(c, t, idx + 1);
17+
if (idx == -1) {
18+
return 0;
19+
}
20+
}
21+
return 1;
22+
}
23+
};

0 commit comments

Comments
 (0)