Advertisement
rishu110067

Untitled

Jan 22nd, 2022 (edited)
1,020
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def dutch_flag_sort(balls):
  2.     red = green = -1
  3.     for blue in range(len(balls)):
  4.         if balls[blue] == "R":
  5.             red += 1
  6.             balls[red], balls[blue] = balls[blue], balls[red]
  7.             green += 1
  8.             if green != red:
  9.                 balls[green], balls[blue] = balls[blue], balls[green]
  10.         elif balls[blue] == "G":
  11.             green += 1
  12.             balls[green], balls[blue] = balls[blue], balls[green]
  13.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement