From 1176c423e824dbcb14cb061b9212ce49c400b5ec Mon Sep 17 00:00:00 2001 From: Mhrooz Date: Fri, 24 May 2024 19:37:30 +0200 Subject: [PATCH] pass 88 and 125 easy --- 125-240524-pass/main.py | 25 ++++++++++++++++++++++++ 88-231127-pass/main.py | 42 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 125-240524-pass/main.py create mode 100644 88-231127-pass/main.py diff --git a/125-240524-pass/main.py b/125-240524-pass/main.py new file mode 100644 index 0000000..0a9ddeb --- /dev/null +++ b/125-240524-pass/main.py @@ -0,0 +1,25 @@ +def isPalindrome(s: str) -> bool: + tmp = s + tmp = tmp.lower() + def is_char(ch): + if (ch >= 'a' and ch <= 'z') or (ch >= '0' and ch <= '9'): + return True + return False + exp = [] + for lt in tmp: + if is_char(lt): + exp.append(lt) + length = len(exp) + for index, ele in enumerate(exp): + if(exp[index] != exp[length - index - 1]): + return False + return True + +s = 'A man, a plan a canal: Panama' +print(isPalindrome(s)) +s = " " +print(isPalindrome(s)) +s = "race a car" +print(isPalindrome(s)) +s = "0P" +print(isPalindrome(s)) \ No newline at end of file diff --git a/88-231127-pass/main.py b/88-231127-pass/main.py new file mode 100644 index 0000000..584550d --- /dev/null +++ b/88-231127-pass/main.py @@ -0,0 +1,42 @@ +def merge(self, nums1: list[int], m: int, nums2: list[int], n: int) -> None: + """ + Do not return anything, modify nums1 in-place instead. + """ + tmp = [] + for i in range(m): + tmp.append(nums1[i]) + for num in nums2: + tmp.append(num) + + ind1 = 0 + ind2 = 0 + rlt = [] + if(m == 0 or n == 0): + rlt += tmp + else: + for i in range(m + n): + if(nums1[ind1]<= nums2[ind2]): + rlt.append(nums1[ind1]) + ind1 += 1 + if(ind1 == m): + rlt += nums2[ind2:] + print(i, rlt) + break + else: + rlt.append(nums2[ind2]) + ind2 += 1 + if(ind2 == n): + rlt += nums1[ind1:] + print(i, rlt) + break; + print(i, rlt) + for i in range(len(rlt)): + nums1[i] = rlt[i] + +nums1 = [2,0] +m = 1 +nums2 = [1] +n = 1 +print(merge(0, nums1, m, nums2, n)) + + \ No newline at end of file