Solved LeetCode program · 93 of 1,000
#0093 · Restore IP Addresses
Original English source
Keep a shared text as empty text. Place "25525511135" into text. Keep a shared parts as an empty list of text. Keep a shared answers as an empty list of text. Keep a shared piece as empty text. Keep a shared partcount of 0. Keep a shared text length as 0. Set text length to 11.
To save piece from start (a whole number) to finish (a whole number). Set piece to the slice of text from start to finish. Place piece into parts. Add 1 to partcount. Restore from finish. Remove the last item from parts. Subtract 1 from partcount.
To restore from position (a whole number). If partcount is 4 and position is text length, The built is join parts with ".", Place built into answers, then return. If partcount is 4, return. If position is text length, return. The first is the digit value of character position of text. The second is 0. If position plus 1 is at most text length, set second to the digit value of character (position plus 1) of text. The third is 0. If position plus 2 is at most text length, set third to the digit value of character (position plus 2) of text. If position is less than text length, save piece from position to position plus 1. If position plus 1 is at most text length and first is not 0, save piece from position to position plus 2. If position plus 2 is at most text length and first is not 0 and first times 100 plus second times 10 plus third is at most 255, save piece from position to position plus 3.
Restore from 0. For each answer in answers, show answer.
Expected stdout
255.255.11.135 255.255.111.35