We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 41307ff + 45aec8c commit 2868340Copy full SHA for 2868340
java/0408-valid-word-abbreviation.java
@@ -0,0 +1,21 @@
1
+class Solution {
2
+ public boolean validWordAbbreviation(String word, String abbr) {
3
+ int i = 0, j = 0;
4
+ while (i < word.length() && j < abbr.length()) {
5
+ if (word.charAt(i) == abbr.charAt(j)) {
6
+ i++;
7
+ j++;
8
+ continue;
9
+ }
10
+ if (abbr.charAt(j) <= '0' || abbr.charAt(j) > '9')
11
+ return false;
12
+ int num = 0;
13
+ while (j < abbr.length() && Character.isDigit(abbr.charAt(j))) {
14
+ num = num * 10 + abbr.charAt(j) - '0';
15
16
17
+ i += num;
18
19
+ return i == word.length() && j == abbr.length();
20
21
+}
0 commit comments