Solved LeetCode program · 198 of 1,000
#0228 · Summary Ranges
Original English source
Keep a shared numbers holding 0, 1, 2, 4, 5, and 7. Keep a shared last of 5. Keep a shared beginslot of 0. Keep a shared finishslot of 0. Keep a shared line as empty text. Keep a shared answers as an empty list of text.
To store. Set line to empty text. The firstlocal is beginslot. The beginvalue is item firstlocal of numbers. The begintext is format whole number beginvalue as text. Place begintext into line. The secondlocal is finishslot. The endvalue is item secondlocal of numbers. The endtext is format whole number endvalue as text. If beginslot is not finishslot, Place "->" into line, Place endtext into line. The copy is a copy of line. Place copy into answers.
For every spot from 0 to last.
The current is item spot of numbers. If spot is 0, set beginslot to spot. If spot is more than 0, The previous is item (spot minus 1) of numbers, If current is not previous plus 1, set beginslot to spot. If spot is last, set finishslot to spot, store. If spot is less than last, The next is item (spot plus 1) of numbers, If next is not current plus 1, set finishslot to spot, store.
For each answer in answers, show answer.
Expected stdout
0->2 4->5 7