diff options
Diffstat (limited to 'challenge-321/packy-anderson/python/ch-2.py')
| -rwxr-xr-x | challenge-321/packy-anderson/python/ch-2.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/challenge-321/packy-anderson/python/ch-2.py b/challenge-321/packy-anderson/python/ch-2.py new file mode 100755 index 0000000000..e1f1bc7c82 --- /dev/null +++ b/challenge-321/packy-anderson/python/ch-2.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python + +import re + +def backspaceCompare(str1, str2): + s1 = re.sub(r'.\#', "", str1) + while s1 != str1: + str1 = s1 + s1 = re.sub(r'.\#', "", str1) + s2 = re.sub(r'.\#', "", str2) + while s2 != str2: + str2 = s2 + s2 = re.sub(r'.\#', "", str2) + return s1 == s2 + +def solution(str1, str2): + print(f'Input: $str1 = "{str1}"') + print(f' $str2 = "{str2}"') + print(f'Output: { backspaceCompare(str1, str2) }') + +print('Example 1:') +solution("ab#c", "ad#c") + +print('\nExample 2:') +solution("ab##", "a#b#") + +print('\nExample 3:') +solution("a#b", "c") |
