From f8ebc59b56edd408f3e5f29d55f5271d84ddb498 Mon Sep 17 00:00:00 2001 From: nghia pham <74634299+nghiab1706989@users.noreply.github.com> Date: Wed, 27 Oct 2021 16:14:38 +0700 Subject: [PATCH] Solved for issue #98 --- 394/README.md | 4 ++++ 394/leetcode394-DecodeString.py | 12 ++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 394/README.md create mode 100644 394/leetcode394-DecodeString.py diff --git a/394/README.md b/394/README.md new file mode 100644 index 0000000..6fc2c5f --- /dev/null +++ b/394/README.md @@ -0,0 +1,4 @@ +# Hi, SpasZahariev! Here is my help . My code is on Python3 scenario +# Use Regex==regular expression is a sequence of characters that specifies a search pattern. + + diff --git a/394/leetcode394-DecodeString.py b/394/leetcode394-DecodeString.py new file mode 100644 index 0000000..ee1223e --- /dev/null +++ b/394/leetcode394-DecodeString.py @@ -0,0 +1,12 @@ +class Solution: + def decodeString(self, s: str) -> str: + import re + patt = "(\d+)\[([a-z]+)\]" + + found = re.findall(patt, s) + while found: + for rep, cnt in found: + s = s.replace(f'{rep}[{cnt}]', cnt * int(rep)) + found = re.findall(patt, s) + + return s \ No newline at end of file