two pass solution. count number of one’s, two’s, three’s in first pass, then fill three types of number in second pass
Error:
N/A
update:
one pass solution:
use three pointer: first-> indicate the element behind it is 0; last-> indicate the element in front of it is 2; cur->indicate current handle element. So if current element is 1, it means it is correct index, if it is 0, swap with first, it it is 2, swap with last