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 9e1ceb2 + 1293b28 commit 2e10c76Copy full SHA for 2e10c76
2018.11.30-leetcode890/张小胖.md
@@ -0,0 +1,29 @@
1
+class Solution {
2
+public:
3
+ vector<string> findAndReplacePattern(vector<string>& words, string pattern) {
4
+ vector<string>res;
5
+ int n = pattern.size();
6
+ for (string &word : words) {
7
+ if (word.size() != n)continue;
8
+ vector<char>pletter(256, '#');
9
+ vector<char>wletter(256, '#');
10
+ bool flag = false;
11
+ //进行映射
12
+ for (int i = 0; i < n; i++) {
13
+ if (pletter[pattern[i]] == '#'&&wletter[word[i]]=='#') {
14
+ pletter[pattern[i]] = word[i];
15
+ wletter[word[i]] = pattern[i];
16
+ }
17
+ else if (pletter[pattern[i]] == word[i]&& wletter[word[i]]==pattern[i]) {
18
+ continue;
19
20
+ else {
21
+ flag = true;
22
+ break;
23
24
25
+ if (!flag)res.push_back(word);
26
27
+ return res;
28
29
+};
0 commit comments