diff --git a/python-solutions/MakeTheStringGreat.py b/python-solutions/MakeTheStringGreat.py new file mode 100644 index 0000000..56b32f2 --- /dev/null +++ b/python-solutions/MakeTheStringGreat.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/PlusOne.py b/python-solutions/PlusOne.py new file mode 100644 index 0000000..9026992 --- /dev/null +++ b/python-solutions/PlusOne.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/RemoveAllAdjacentDuplicatesInString.py b/python-solutions/RemoveAllAdjacentDuplicatesInString.py new file mode 100644 index 0000000..175e92e --- /dev/null +++ b/python-solutions/RemoveAllAdjacentDuplicatesInString.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/RemoveDuplicatesfromSortedArray.py b/python-solutions/RemoveDuplicatesfromSortedArray.py new file mode 100644 index 0000000..929dfd6 --- /dev/null +++ b/python-solutions/RemoveDuplicatesfromSortedArray.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/RemoveElement.py b/python-solutions/RemoveElement.py new file mode 100644 index 0000000..eacc9ea --- /dev/null +++ b/python-solutions/RemoveElement.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/TwoSum.py b/python-solutions/TwoSum.py new file mode 100644 index 0000000..0d478e3 --- /dev/null +++ b/python-solutions/TwoSum.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/ValidParentheses.py b/python-solutions/ValidParentheses.py new file mode 100644 index 0000000..4bf59ff --- /dev/null +++ b/python-solutions/ValidParentheses.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