The TransCompilator

Solved LeetCode program · 67 of 1,000

#0067 · Add Binary

Easy String chunk-02.md

Original English source

The source is "11". The target is "1". The lastsource is the last position of source. The lasttarget is the last position of target. The position is lastsource. The mark is lasttarget. The carry is 0. The reversedresult is empty text.
Repeat while position is at least 0 or mark is at least 0 or carry is 1.
The sum is carry. The digit is 0. If position is at least 0, set digit to the digit value of character position of source. If position is at least 0, add digit to sum. If position is at least 0, set position to one less than position. If mark is at least 0, set digit to the digit value of character mark of target. If mark is at least 0, add digit to sum. If mark is at least 0, set mark to one less than mark. The bit is the character for sum modulo 2. Place bit into reversedresult. Set carry to sum divided by 2.

The result is empty text. The reversedlast is the last position of reversedresult. For every step from 0 to reversedlast, The number is reversedlast minus step, Place character number of reversedresult into result. Display result.

Open in Playground Browse all 1,000 problems

Expected stdout

100