Long Pressed Name LeetCode solution in Java

1
class Solution {
2
public boolean isLongPressedName(String name, String typed) {
3
int i = 0;
4
int j = 0;
5
int m = name.length();
6
int n = typed.length();
7

8
while (j < n) {
9
if (i < m && name.charAt(i) == typed.charAt(j)) {
10
i++;
11
j++;
12
} else if (j > 0 && typed.charAt(j) == typed.charAt(j - 1)) {
13
j++;
14
} else {
15
return false;
16
}
17
}
18

19
return i == m;
20
}
21
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0