-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIsSubsequence.cs
41 lines (33 loc) · 931 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace LeetCodeSolutions
{
// Source: https://leetcode.com/problems/is-subsequence/
// Author: Jalal Shabo
// Date : 11/28/2023
// Time Complexity: O(n) one look through string
// Space Complexity: O(n)
public static class IsSubsequence
{
public static bool IsSubsequenceSolution(string s, string t)
{
if (s.Length == 0)
{
return true;
}
if (t.Length == 0)
{
return false;
}
int currentCharIndex = 0;
foreach (char letter in t)
{
if (s[currentCharIndex] == letter) currentCharIndex++;
if (currentCharIndex == s.Length) return true;
}
return false;
}
}
}