Skip to content

Commit 0dc5611

Browse files
authored
Merge pull request #2 from Saul-Zhang/Saul-Zhang-patch-1
Create Saul.md
2 parents 7b62a24 + 3b626b9 commit 0dc5611

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

2018.11.30-leetcode890/Saul.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
```java
2+
public class Solution {
3+
public static List<String> findAndReplacePattern(String[] words, String pattern) {
4+
List<String> result = new ArrayList<>();
5+
boolean flag = false;
6+
for (String word : words) {
7+
if (word.length() != pattern.length()) {
8+
continue;
9+
}
10+
flag = false;
11+
char[] wordChars = word.toCharArray();
12+
char[] patternChars = pattern.toCharArray();
13+
//比较wordChars第i个位置与第j个位置的值,如果相同,那么patternChars第i个位置与第j个位置的值也要相同
14+
//如果wordChars第i个位置与第j个位置的值不同,那么patternChars第i个位置与第j个位置的值也要不同
15+
for (int i = 0; i < wordChars.length ; i++) {
16+
for (int j = i + 1; j < wordChars.length; j++) {
17+
if (wordChars[i] == wordChars[j]) {
18+
if (patternChars[i] != patternChars[j]) {
19+
flag = true;
20+
break;
21+
}
22+
}
23+
24+
if (wordChars[i] != wordChars[j]) {
25+
if (patternChars[i] == patternChars[j]) {
26+
flag = true;
27+
break;
28+
}
29+
}
30+
}
31+
}
32+
33+
if (!flag) {
34+
result.add(word);
35+
}
36+
}
37+
return result;
38+
}
39+
}
40+
41+
```

0 commit comments

Comments
 (0)