<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:
    def numberToWords(self,num: int) -> str:
        if num == 0: return "Zero"
        digits = list(map(int,str(num)))[::-1]
        if len(digits) % 3 == 2: digits.append(0) #make it a multiple of 3
        elif len(digits) % 3 == 1: 
            digits.append(0)
            digits.append(0)

        #words
        # "Hundred"
        u_digit = ["","One","Two","Three","Four","Five","Six","Seven","Eight","Nine",
                "Ten","Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen"]
        d_digit = ["","","Twenty","Thirty","Forty","Fifty","Sixty","Seventy","Eighty","Ninety"]
        scale = ["","Thousand","Million","Billion"]

        res = []
        scale_id = 0
        for i in range(0,len(digits),3):
            val = ""
            #centenas
            if digits[i+2] > 0: val += f"{u_digit[digits[i+2]]} Hundred " if digits[i+1] != 0 or digits[i] != 0 else f"{u_digit[digits[i+2]]} Hundred"
            #dezenas
            if digits[i+1] < 2: 
                number = digits[i+1]*10+digits[i]
                val += f"{u_digit[number]}"
            #unidades
            else:   
                val += f"{d_digit[digits[i+1]]}{u_digit[digits[i]]}" if digits[i+1] == 0 or digits[i] == 0 else f"{d_digit[digits[i+1]]} {u_digit[digits[i]]}"
            
            if scale_id != 0 and val != "":
                print(val)
                val += f" {scale[scale_id]}"

            res.insert(0,val.strip())
            scale_id += 1
            
        res = [item for item in res if item != ""]
        return " ".join(res).strip()
15900