Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd174258

Browse files
committed
Added Long Pressed Name.java
1 parentc7eca3a commitd174258

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

‎Easy/Long Pressed Name.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
classSolution {
2+
publicbooleanisLongPressedName(Stringname,Stringtyped) {
3+
intnameIdx =0;
4+
inttypeIdx =0;
5+
intnameLen =name.length();
6+
inttypeLen =typed.length();
7+
while (nameIdx <nameLen &&typeIdx <typeLen) {
8+
if (name.charAt(nameIdx) !=typed.charAt(typeIdx)) {
9+
returnfalse;
10+
}
11+
while (nameIdx <nameLen &&typeIdx <typeLen &&name.charAt(nameIdx) ==typed.charAt(typeIdx)) {
12+
nameIdx++;
13+
typeIdx++;
14+
}
15+
charprev =name.charAt(nameIdx -1);
16+
while (typeIdx <typeLen &&typed.charAt(typeIdx) ==prev) {
17+
typeIdx++;
18+
}
19+
}
20+
returnnameIdx ==nameLen &&typeIdx ==typeLen;
21+
}
22+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp