<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>

class Solution {
    static constexpr string_view units[]{
        "", "One ", "Two ", "Three ", "Four ",
        "Five ", "Six ", "Seven ", "Eight ", "Nine ",
        "Ten ", "Eleven ", "Twelve ", "Thirteen ", "Fourteen ",
        "Fifteen ", "Sixteen ", "Seventeen ", "Eighteen ", "Nineteen ",
    };

    static constexpr string_view tens[]{
        "", "Ten ", "Twenty ", "Thirty ", "Forty ",
        "Fifty ", "Sixty ", "Seventy ", "Eighty ", "Ninety ",
    };

    void convert1000(string& res, int num) {
        if (num == 0) return;

        if (num >= 100) {
            res += units[num / 100];
            res += "Hundred ";
            num %= 100;
        }

        if (num == 0) return;

        if (num < size(units)) {
            res += units[num];
            return;
        }

        if (num >= 10) {
            res += tens[num / 10];
            num %= 10;
        }

        if (num == 0) return;

        res += units[num];
    }

public:
    string numberToWords(int num) {
        if (num == 0) return "Zero";
        string res;
        if (num >= 1000000000) {
            convert1000(res, num / 1000000000);
            num %= 1000000000;
            res += "Billion ";
        }
        if (num >= 1000000) {
            convert1000(res, num / 1000000);
            num %= 1000000;
            res += "Million ";
        }
        if (num >= 1000) {
            convert1000(res, num / 1000);
            num %= 1000;
            res += "Thousand ";
        }
        convert1000(res, num);
        res.pop_back();
        return res;
    }
};
7600