From 92f198d46948f6b34e8abd1e68ab8f2bd36be644 Mon Sep 17 00:00:00 2001 From: Omer Ahat Date: Thu, 13 Jul 2023 17:52:56 +0300 Subject: [PATCH 1/2] python solutions added --- python-solutions/Make The String Great.py | 15 +++++++++++++++ python-solutions/Plus One.py | 3 +++ .../Remove All Adjacent Duplicates In String.py | 9 +++++++++ .../Remove Duplicates from Sorted Array.py | 7 +++++++ python-solutions/Remove Element.py | 8 ++++++++ python-solutions/Two Sum.py | 6 ++++++ python-solutions/Valid Parentheses.py | 7 +++++++ 7 files changed, 55 insertions(+) create mode 100644 python-solutions/Make The String Great.py create mode 100644 python-solutions/Plus One.py create mode 100644 python-solutions/Remove All Adjacent Duplicates In String.py create mode 100644 python-solutions/Remove Duplicates from Sorted Array.py create mode 100644 python-solutions/Remove Element.py create mode 100644 python-solutions/Two Sum.py create mode 100644 python-solutions/Valid Parentheses.py diff --git a/python-solutions/Make The String Great.py b/python-solutions/Make The String Great.py new file mode 100644 index 0000000..56b32f2 --- /dev/null +++ b/python-solutions/Make The String Great.py @@ -0,0 +1,15 @@ +def makeGood(s): + stack=[] + for char in s: + if stack: + if (char.isupper() and stack[-1].islower() and stack[-1].upper() == char )or (char.islower() and stack[-1].isupper() and stack[-1].lower() == char): + stack.pop() + continue + else: + stack.append(char) + + else: + stack.append(char) + + + return "".join(stack) diff --git a/python-solutions/Plus One.py b/python-solutions/Plus One.py new file mode 100644 index 0000000..9026992 --- /dev/null +++ b/python-solutions/Plus One.py @@ -0,0 +1,3 @@ +def plusOne(digits): + number = int(''.join(map(str, digits))) + return [int(digit) for digit in str(number+1)] diff --git a/python-solutions/Remove All Adjacent Duplicates In String.py b/python-solutions/Remove All Adjacent Duplicates In String.py new file mode 100644 index 0000000..175e92e --- /dev/null +++ b/python-solutions/Remove All Adjacent Duplicates In String.py @@ -0,0 +1,9 @@ +def removeDuplicates(s): + stack=[] + for char in s: + if stack and stack[-1] == char: + stack.pop() + else: + stack.append(char) + + return "".join(stack) diff --git a/python-solutions/Remove Duplicates from Sorted Array.py b/python-solutions/Remove Duplicates from Sorted Array.py new file mode 100644 index 0000000..929dfd6 --- /dev/null +++ b/python-solutions/Remove Duplicates from Sorted Array.py @@ -0,0 +1,7 @@ +def removeDuplicates(nums): + k = 1 + for i in range(1, len(nums)): + if nums[i] != nums[i - 1]: + nums[k] = nums[i] + k += 1 + return k diff --git a/python-solutions/Remove Element.py b/python-solutions/Remove Element.py new file mode 100644 index 0000000..eacc9ea --- /dev/null +++ b/python-solutions/Remove Element.py @@ -0,0 +1,8 @@ +def removeElement(nums,val): + + if nums==[]: + return 0 + + while nums.count(val)!=0: + nums.remove(val) + return len(nums) diff --git a/python-solutions/Two Sum.py b/python-solutions/Two Sum.py new file mode 100644 index 0000000..0d478e3 --- /dev/null +++ b/python-solutions/Two Sum.py @@ -0,0 +1,6 @@ +def twoSum(nums,target): + for i in range(len(nums)): + complement = target - nums[i] + if complement in nums and nums.index(complement) != i: + complement_index = nums.index(complement) + return [i,complement_index] diff --git a/python-solutions/Valid Parentheses.py b/python-solutions/Valid Parentheses.py new file mode 100644 index 0000000..4bf59ff --- /dev/null +++ b/python-solutions/Valid Parentheses.py @@ -0,0 +1,7 @@ +def isValid(s): + while len(s) > 0: + l = len(s) + s = s.replace('()','').replace('{}','').replace('[]','') + if l==len(s): + return False + return True \ No newline at end of file From e81e3a78132ac81ea02516ffb6a57cd4dad05c92 Mon Sep 17 00:00:00 2001 From: Omer Ahat Date: Fri, 14 Jul 2023 13:47:03 +0300 Subject: [PATCH 2/2] PascalCase --- .../{Make The String Great.py => MakeTheStringGreat.py} | 0 python-solutions/{Plus One.py => PlusOne.py} | 0 ...icates In String.py => RemoveAllAdjacentDuplicatesInString.py} | 0 ...es from Sorted Array.py => RemoveDuplicatesfromSortedArray.py} | 0 python-solutions/{Remove Element.py => RemoveElement.py} | 0 python-solutions/{Two Sum.py => TwoSum.py} | 0 python-solutions/{Valid Parentheses.py => ValidParentheses.py} | 0 7 files changed, 0 insertions(+), 0 deletions(-) rename python-solutions/{Make The String Great.py => MakeTheStringGreat.py} (100%) rename python-solutions/{Plus One.py => PlusOne.py} (100%) rename python-solutions/{Remove All Adjacent Duplicates In String.py => RemoveAllAdjacentDuplicatesInString.py} (100%) rename python-solutions/{Remove Duplicates from Sorted Array.py => RemoveDuplicatesfromSortedArray.py} (100%) rename python-solutions/{Remove Element.py => RemoveElement.py} (100%) rename python-solutions/{Two Sum.py => TwoSum.py} (100%) rename python-solutions/{Valid Parentheses.py => ValidParentheses.py} (100%) diff --git a/python-solutions/Make The String Great.py b/python-solutions/MakeTheStringGreat.py similarity index 100% rename from python-solutions/Make The String Great.py rename to python-solutions/MakeTheStringGreat.py diff --git a/python-solutions/Plus One.py b/python-solutions/PlusOne.py similarity index 100% rename from python-solutions/Plus One.py rename to python-solutions/PlusOne.py diff --git a/python-solutions/Remove All Adjacent Duplicates In String.py b/python-solutions/RemoveAllAdjacentDuplicatesInString.py similarity index 100% rename from python-solutions/Remove All Adjacent Duplicates In String.py rename to python-solutions/RemoveAllAdjacentDuplicatesInString.py diff --git a/python-solutions/Remove Duplicates from Sorted Array.py b/python-solutions/RemoveDuplicatesfromSortedArray.py similarity index 100% rename from python-solutions/Remove Duplicates from Sorted Array.py rename to python-solutions/RemoveDuplicatesfromSortedArray.py diff --git a/python-solutions/Remove Element.py b/python-solutions/RemoveElement.py similarity index 100% rename from python-solutions/Remove Element.py rename to python-solutions/RemoveElement.py diff --git a/python-solutions/Two Sum.py b/python-solutions/TwoSum.py similarity index 100% rename from python-solutions/Two Sum.py rename to python-solutions/TwoSum.py diff --git a/python-solutions/Valid Parentheses.py b/python-solutions/ValidParentheses.py similarity index 100% rename from python-solutions/Valid Parentheses.py rename to python-solutions/ValidParentheses.py