aboutsummaryrefslogtreecommitdiffstats
path: root/890/main.py
diff options
context:
space:
mode:
authorterminaldweller <thabogre@gmail.com>2022-07-29 05:02:02 +0000
committerterminaldweller <thabogre@gmail.com>2022-07-29 05:02:02 +0000
commit0b232d3f2e6516374ffb09ea36ab4a2f2104a6f2 (patch)
treec6e26d6cf51ed201b90852747b0ae1d7c512a7fe /890/main.py
parentupdate (diff)
downloadleetcode-0b232d3f2e6516374ffb09ea36ab4a2f2104a6f2.tar.gz
leetcode-0b232d3f2e6516374ffb09ea36ab4a2f2104a6f2.zip
update
Diffstat (limited to '890/main.py')
-rwxr-xr-x890/main.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/890/main.py b/890/main.py
new file mode 100755
index 0000000..2082679
--- /dev/null
+++ b/890/main.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python3
+
+from typing import List
+
+
+class Solution:
+ @staticmethod
+ def findAndReplacePattern(words: List[str], pattern: str) -> List[str]:
+ def match(w):
+ m1, m2 = {}, {}
+ return all(
+ (m1.setdefault(i, j), m2.setdefault(j, i)) == (j, i)
+ for i, j in zip(w, pattern)
+ )
+
+ results = []
+ for result in filter(match, words):
+ results.append(result)
+ return results
+
+
+def main():
+ words = ["abc", "deq", "mee", "aqq", "dkd", "ccc"]
+ pattern = "abb"
+ print(Solution.findAndReplacePattern(words, pattern))
+
+
+if __name__ == "__main__":
+ main()