Skip to content

Commit 8f121a3

Browse files
author
liwentian
committed
fd
1 parent 357cc11 commit 8f121a3

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@
296296
|404|[Sum of Left Leaves](https://leetcode.com/problems/sum-of-left-leaves/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/SumOfLeftLeaves.java)|80|
297297
|406|[Queue Reconstruction by Height](https://leetcode.com/problems/queue-reconstruction-by-height/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/QueueReconstructionByHeight.java)|60|这题开始没思路,多做几遍|
298298
|407|[Trapping Rain Water II](https://leetcode.com/problems/trapping-rain-water-ii/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/TrappingRainWaterII.java)||
299+
|408|[Valid Word Abbreviation](https://leetcode.com/problems/valid-word-abbreviation/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/validWordAbbreviation.java)|80|多做两遍|
299300
|409|[Longest Palindrome](https://leetcode.com/problems/longest-palindrome/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/LongestPalindrome.java)||
300301
|410|[Split Array Largest Sum](https://leetcode.com/problems/split-array-largest-sum)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/SplitArrayLargestSum.java)||
301302
|412|[Fizz Buzz](https://leetcode.com/problems/fizz-buzz/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/FizzBuzz.java)|100|
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.inuker.solution;
2+
3+
/**
4+
* Created by liwentian on 2017/9/6.
5+
*/
6+
7+
public class ValidWordAbbreviation {
8+
9+
public boolean validWordAbbreviation(String word, String abbr) {
10+
int i = 0, j = 0;
11+
for (int value = 0; i < word.length() && j < abbr.length(); ) {
12+
if (word.charAt(i) == abbr.charAt(j)) {
13+
i++; j++;
14+
continue;
15+
}
16+
17+
if (abbr.charAt(j) <= '0' || abbr.charAt(j) > '9') {
18+
return false;
19+
}
20+
21+
for (value = 0; j < abbr.length() && abbr.charAt(j) >= '0' && abbr.charAt(j) <= '9'; j++) {
22+
value = value * 10 + (abbr.charAt(j) - '0');
23+
}
24+
i += value;
25+
}
26+
return i == word.length() && j == abbr.length();
27+
}
28+
}

test/src/main/java/com/example/Main.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.inuker.solution.FactorCombinations;
44
import com.inuker.solution.RestoreIPAddresses;
5+
import com.inuker.solution.ValidWordAbbreviation;
56
import com.leetcode.google.DecodeString;
67
import com.leetcode.google.GenerateParentheses;
78
import com.leetcode.google.MissingRanges;
@@ -28,14 +29,8 @@
2829
public class Main {
2930

3031
public static void main(String[] args) {
31-
List<List<Integer>> lists = new FactorCombinations().getFactors(128);
32-
// List<List<Integer>> lists = new FactorCombinations().getFactors(23848713);
33-
for (List<Integer> list : lists) {
34-
for (Integer n : list) {
35-
System.out.print(n + " ");
36-
}
37-
System.out.println();
38-
}
32+
boolean b = new ValidWordAbbreviation().validWordAbbreviation2("a", "01");
33+
System.out.println(b);
3934
}
4035
}
4136

0 commit comments

Comments
 (0)