-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution_500.java
More file actions
34 lines (30 loc) · 964 Bytes
/
Solution_500.java
File metadata and controls
34 lines (30 loc) · 964 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package com.hilbert25.leetcode;
import java.util.ArrayList;
import java.util.List;
/**
* @author : hilbert25
* @version 创建时间:2017年4月28日 下午3:34:18 LeetCode com.hilbert25.leetcode
* Solution_500
*/
public class Solution_500 {
public static void main(String[] args) {
String[] res = findWords(new String[] {});
for (String s : res)
System.out.println(s);
}
public static String[] findWords(String[] words) {
int[] pos = new int[] { 1, 2, 2, 1, 0, 1, 1, 1, 0, 1, 1, 1, 2, 2, 0, 0, 0, 0, 1, 0, 0, 2, 0, 2, 0, 2 };
List<String> list = new ArrayList<String>();
for (int i = 0; i < words.length; i++) {
String str = words[i].toLowerCase();
int line = pos[str.charAt(0) - 'a'];
int index = 1;
while (index < str.length() && pos[str.charAt(index) - 'a'] == line)
index++;
if (index == str.length())
list.add(words[i]);
}
String[] res = new String[list.size()];
return list.toArray(res);
}
}