-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path27th day
38 lines (38 loc) · 847 Bytes
/
27th day
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
class Solution
{
public
boolean isLongPressedName(String name, String typed)
{
if (name.length() > typed.length())
{
return false;
}
int i = 0;
int j = 0;
while (i < name.length() && j < typed.length())
{
if (name.charAt(i) == typed.charAt(j))
{
i++;
j++;
}
else if (i > 0 && name.charAt(i - 1) == typed.charAt(j))
{
j++;
}
else
{
return false;
}
}
while (j < typed.length())
{
if (name.charAt(i - 1) != typed.charAt(j))
{
return false;
}
j++;
}
return i < name.length() ? false : true;
}
}