-
-
Notifications
You must be signed in to change notification settings - Fork 300
/
392.cpp
51 lines (49 loc) · 1.31 KB
/
392.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
__________________________________________________________________________________________________
sample 12 ms submission
class Solution {
public:
bool isSubsequence(string s, string t) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n=t.length();
int m=s.length();
if(m==0)return true;
if(n==0||n<m)return false;
int i=0,j=0;
char c=s[j];
while(i<n)
{
while((i<n)&&(t[i]!=c))i++;
if(i==n)
{
return false;
}
else
{
j++;
if(j==m)return true;
else c=s[j];
}
i++;
}
return false;
}
};
__________________________________________________________________________________________________
sample 16900 kb submission
class Solution {
public:
bool isSubsequence(string s, string t) {
int i = 0, j = 0, m = s.size(), n = t.size();
if (m > n) return false;
while (i < m && j < n) {
if (s[i] == t[j]) {
++i;
}
++j;
}
return i == m;
}
};
__________________________________________________________________________________________________