Skip to content

Commit

Permalink
daily
Browse files Browse the repository at this point in the history
  • Loading branch information
Zanger67 committed Aug 2, 2024
1 parent 72995e7 commit 1063e46
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions my-submissions/m2134.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class Solution:
def minSwaps(self, nums: List[int]) -> int:
totalOnes = nums.count(1)
if not totalOnes :
return 0

oneCount = nums[:totalOnes].count(1)
zeroCount = totalOnes - oneCount
minMoves = zeroCount

for i, nxtVal in enumerate(nums[totalOnes:] + nums[:totalOnes], totalOnes) :
if nxtVal :
oneCount += 1
else :
zeroCount += 1

if nums[i - totalOnes] :
oneCount -= 1
else :
zeroCount -= 1

minMoves = min(minMoves, zeroCount)

return minMoves
git p

0 comments on commit 1063e46

Please sign in to comment.