We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 791d95e + d1e34ce commit f898e1eCopy full SHA for f898e1e
2018.11.30-leetcode890/syuan.md
@@ -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