<p>Convert a non-negative integer <code>num</code> to its English words representation.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> num = 123
<strong>Output:</strong> &quot;One Hundred Twenty Three&quot;
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> num = 12345
<strong>Output:</strong> &quot;Twelve Thousand Three Hundred Forty Five&quot;
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> num = 1234567
<strong>Output:</strong> &quot;One Million Two Hundred Thirty Four Thousand Five Hundred Sixty Seven&quot;
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>0 &lt;= num &lt;= 2<sup>31</sup> - 1</code></li>
</ul>

const string digits[] = { "-", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine" };
const string specialTwoDigitsNames[] = { "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen" };
const string tens[] = { "-", "Ten", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety" };

class Solution {
private:
    string result;

public:
    string numberToWords(int num) {
        if (num == 0) return "Zero";

        if (num >= 1e9) {
            threeDigitsToWords(num / (int) 1e9);
            addWord("Billion");
            num %= (int) 1e9;
        }

        if (num >= 1e6) {
            threeDigitsToWords(num / (int) 1e6);
            addWord("Million");
            num %= (int) 1e6;
        }

        if (num >= 1e3) {
            threeDigitsToWords(num / (int) 1e3);
            addWord("Thousand");
            num %= (int) 1e3;
        }

        threeDigitsToWords(num % 1000);
        return result;
    }

private:
    void threeDigitsToWords(int num) {
        if (num >= 100) {
            addWord(digits[num / 100]);
            addWord("Hundred");
            num %= 100;
        }

        if (num >= 11 && num <= 19) {
            addWord(specialTwoDigitsNames[num - 11]);
        } else {
            if (num >= 10) {
                addWord(tens[num / 10]);
                num %= 10;
            }

            if (num > 0) {
                addWord(digits[num]);
            }
        }
    }

    void addWord(const string& word) {
        if (!result.empty()) {
            result += ' ';
        }

        result += word;
    }
};

8300