-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathIsSubSequence.cs
42 lines (25 loc) · 967 Bytes
/
IsSubSequence.cs
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
public class Solution {
public bool IsSubsequence(string s, string t) {
//inisialisasi 2 pointer.
//link problem : https://leetcode.com/problems/is-subsequence/
if(s == String.Empty){
return true;
}else if(t == String.Empty){
return false;
}
int left_pointer = 0; //short string
int right_pointer = 0; //long string
while(right_pointer < t.Length)
{
if(s[left_pointer] == t[right_pointer])
{
left_pointer++;
if(left_pointer >= s.Length){
return true;
}
}
right_pointer++;
}
return false;
}
}