Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions python-solutions/MakeTheStringGreat.py
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 3 additions & 0 deletions python-solutions/PlusOne.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def plusOne(digits):
number = int(''.join(map(str, digits)))
return [int(digit) for digit in str(number+1)]
9 changes: 9 additions & 0 deletions python-solutions/RemoveAllAdjacentDuplicatesInString.py
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 7 additions & 0 deletions python-solutions/RemoveDuplicatesfromSortedArray.py
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions python-solutions/RemoveElement.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def removeElement(nums,val):

if nums==[]:
return 0

while nums.count(val)!=0:
nums.remove(val)
return len(nums)
6 changes: 6 additions & 0 deletions python-solutions/TwoSum.py
Original file line number Diff line number Diff line change
@@ -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]
7 changes: 7 additions & 0 deletions python-solutions/ValidParentheses.py
Original file line number Diff line number Diff line change
@@ -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