Skip to content

Commit f898e1e

Browse files
authored
Merge pull request gzc426#178 from Syuan-Cheng/master
syuan
2 parents 791d95e + d1e34ce commit f898e1e

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

2018.11.30-leetcode890/syuan.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
```
2+
class Solution {
3+
public List<String> findAndReplacePattern(String[] words, String pattern) {
4+
List<String> result=new LinkedList<>();
5+
int pHashCode=getHashCode(pattern);
6+
for (String word : words) {
7+
if (getHashCode(word)==pHashCode) {
8+
result.add(word);
9+
}
10+
}
11+
return result;
12+
}
13+
14+
public int getHashCode(String word){
15+
int[] arr=new int[26];
16+
int hashCode=0,i=1;
17+
for (char c : word.toCharArray()) {
18+
if (arr[c-'a']==0) {
19+
arr[c-'a']=i++;
20+
}
21+
hashCode=hashCode*11+arr[c-'a'];
22+
}
23+
return hashCode;
24+
}
25+
}
26+
```

0 commit comments

Comments
 (0)