8000 Sync LeetCode submission - Long Pressed Name (java) · thatbeautifuldream/leetcode-sync@05fcf09 · GitHub
[go: up one dir, main page]

Skip to content

Commit 05fcf09

Browse files
Sync LeetCode submission - Long Pressed Name (java)
1 parent 1b1471d commit 05fcf09

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution {
2+
public boolean isLongPressedName(String name, String typed) {
3+
if(name.length() > typed.length()) {
4+
return false;
5+
}
6+
int i = 0, j = 0;
7+
while(i < name.length() && j < typed.length()) {
8+
if(name.charAt(i) == typed.charAt(j)) {
9+
i++;
10+
j++;
11+
} else if(i > 0 && name.charAt(i - 1) == typed.charAt(j)) {
12+
j++;
13+
} else {
14+
return false;
15+
}
16+
}
17+
while(j < typed.length()) {
18+
if(name.charAt(i - 1) != typed.charAt(j)) return false;
19+
j++;
20+
}
21+
return i < name.length() ? false : true;
22+
}
23+
}

0 commit comments

Comments
 (0)
0