Solved LeetCode program · 237 of 1,000
#0316 · Remove Duplicate Letters
Original English source
Keep a shared source as empty text. Keep a shared alphabet as empty text. Keep a shared symbol as empty text. Keep a shared picked as empty text. Keep a shared stack as empty text. Keep a shared lasts as empty list of whole numbers. Keep a shared used as empty list of whole numbers. Keep a shared position of 0. Keep a shared marks as an empty list of whole numbers. Place 0 into marks. Place "bcabc" into source. Place "abcdefghijklmnopqrstuvwxyz" into alphabet.
For every spot from 0 to 25.
Place 0 into lasts. Place 0 into used.
To locate from spot (a whole number). If spot is more than 25, return. The letter is the slice of alphabet from spot to spot plus 1. If letter matches symbol, set position to spot, return. Locate from spot plus 1.
To settle from spot (a whole number). If the length of stack is less than 1, Place picked into stack, set item (item 0 of marks) of used to 1, return. The topstart is the last position of stack. The topfinish is topstart plus 1. The top is the slice of stack from topstart to topfinish. Set symbol to empty text. Place top into symbol. Locate from 0. The topindex is position. The can is 0. If item topindex of lasts is more than spot, set can to 1. If symbol comes before picked, set can to 0. If can is 0, Place picked into stack, set item (item 0 of marks) of used to 1, return. Remove last character from stack. Set item topindex of used to 0. Settle from spot.
For every spot from 0 to 4.
The piece is the slice of source from spot to spot plus 1. Set symbol to empty text. Place piece into symbol. Locate from 0. Set item position of lasts to spot.
For every spot from 0 to 4.
The piece is the slice of source from spot to spot plus 1. Set symbol to empty text. Place piece into symbol. Locate from 0. Set item 0 of marks to position. Set picked to empty text. Place piece into picked. If item (item 0 of marks) of used is 0, settle from spot.
Show stack.
Expected stdout
abc