-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path0925-LongPressedName.cs
36 lines (33 loc) · 1 KB
/
0925-LongPressedName.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
//-----------------------------------------------------------------------------
// Runtime: 72ms
// Memory Usage: 22.1 MB
// Link: https://leetcode.com/submissions/detail/352808891/
//-----------------------------------------------------------------------------
namespace LeetCode
{
public class _0925_LongPressedName
{
public bool IsLongPressedName(string name, string typed)
{
int i = 0, j = 0;
while (i < name.Length && j < typed.Length)
{
if (name[i] == typed[j])
{
i++;
j++;
}
else
{
if (j > 0 && typed[j] == typed[j - 1])
j++;
else
return false;
}
}
while (j < typed.Length && j > 0 && typed[j] == typed[j - 1])
j++;
return i == name.Length && j == typed.Length;
}
}
}