Solved LeetCode program · 987 of 1,000
#1363 · Largest Multiple of Three
Original English source
The digits is a list of 8, 1, and 9. Keep a shared counts as an empty list of whole numbers.
For every digit from 0 to 9.
Place 0 into counts.
The total is 0.
For each digit in digits.
Increase item digit of counts by 1. Add digit to total.
The remainder is total modulo 3. Keep a shared taken of 0. Keep a shared line as empty text.
To removeone from kind (a whole number). Set taken to 0. The digit is 0.
Repeat while digit is at most 9.
If item digit of counts is more than 0 and digit modulo 3 is kind, set item digit of counts to item digit of counts minus 1, set taken to 1, stop. Add 1 to digit.
To drop from kind (a whole number). Removeone from kind. Removeone from kind.
To emit from digit (a whole number). The many is item digit of counts.
Repeat while many is more than 0.
Place format whole number digit as text into line. Subtract 1 from many.
If remainder is 1, Removeone from 1. If remainder is 1 and taken is 0, Drop from 2. If remainder is 2, Removeone from 2. If remainder is 2 and taken is 0, Drop from 1.
The high is -1.
For every digit from 0 to 9.
If item digit of counts is more than 0, set high to digit.
If high is more than 0.
For every step from 0 to 9.
The digit is 9 minus step. Emit from digit.
If high is more than 0, show line.
If high is 0, show 0.
Expected stdout
981