We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c7eca3a commit d174258Copy full SHA for d174258
Easy/Long Pressed Name.java
@@ -0,0 +1,22 @@
1
+class Solution {
2
+ public boolean isLongPressedName(String name, String typed) {
3
+ int nameIdx = 0;
4
+ int typeIdx = 0;
5
+ int nameLen = name.length();
6
+ int typeLen = typed.length();
7
+ while (nameIdx < nameLen && typeIdx < typeLen) {
8
+ if (name.charAt(nameIdx) != typed.charAt(typeIdx)) {
9
+ return false;
10
+ }
11
+ while (nameIdx < nameLen && typeIdx < typeLen && name.charAt(nameIdx) == typed.charAt(typeIdx)) {
12
+ nameIdx++;
13
+ typeIdx++;
14
15
+ char prev = name.charAt(nameIdx - 1);
16
+ while (typeIdx < typeLen && typed.charAt(typeIdx) == prev) {
17
18
19
20
+ return nameIdx == nameLen && typeIdx == typeLen;
21
22
+}
0 commit comments