<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 {
public:
    string numberToWords(int num) {
    if(num == 0) return "Zero";

    std::unordered_map<int, std::string> word_map = {
        {0, ""},
        {1, "One "},
        {2, "Two "},
        {3, "Three "},
        {4, "Four "},
        {5, "Five "},
        {6, "Six "},
        {7, "Seven "},
        {8, "Eight "},
        {9, "Nine "},
        {10, "Ten "},
        {11, "Eleven "},
        {12, "Twelve "},
        {13, "Thirteen "},
        {14, "Fourteen "},
        {15, "Fifteen "},
        {16, "Sixteen "},
        {17, "Seventeen "},
        {18, "Eighteen "},
        {19, "Nineteen "},
        {20, "Twenty "},
        {30, "Thirty "},
        {40, "Forty "},
        {50, "Fifty "},
        {60, "Sixty "},
        {70, "Seventy "},
        {80, "Eighty "},
        {90, "Ninety "},
        {-1, "Thousand "},
        {-2, "Million "},
        {-3, "Billion "},
        {-4, "Trillion "}
    };

    std::string result = "";

    if (word_map.find(num) != word_map.end())
    {
        result = word_map[num];
        result.pop_back();
        return result;
    }

    std::string current_string;
    int current_num, count = 0;
    while(num != 0)
    {
        current_string = "";
        current_num = num % 1000;
        num /= 1000;

        if (current_num >= 100) 
        {
            current_string = word_map[current_num/100] + "Hundred " + current_string;
            current_num = current_num%100;
        }
        if (word_map.find(current_num) != word_map.end())
        {
            current_string = current_string + word_map[current_num];
        }
        else
        {
            current_string = current_string + word_map[(current_num/10)*10] + word_map[current_num%10];
        }
        if(current_string != "")current_string = current_string + word_map[count];
        result = current_string + result;
        --count;
    }
    result.pop_back();
    return result;
    }
};
12400