Skip to content

Commit

Permalink
Added solution for Sort Colors
Browse files Browse the repository at this point in the history
  • Loading branch information
Blacknahil committed Jan 9, 2024
1 parent b3faae3 commit e7f7dba
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions week5/sort-colors.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
class Solution:
def sortColors(self, nums: List[int]) -> None:
"""
Do not return anything, modify nums in-place instead.
"""
# lets use bubble sort
n=len(nums)
for i in range(n):
for j in range(n-i-1):
if nums[j]> nums[j+1]:
nums[j],nums[j+1]=nums[j+1],nums[j]
return nums
count=[0]*3
for i in nums:
count[i]+=1
pointer=0
for i in range(len(count)):
while count[i] >0:
nums[pointer]=i
count[i]-=1
pointer+=1



0 comments on commit e7f7dba

Please sign in to comment.