You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
'''[8:41] StartThoughts (Didn't execute since not sure?): Use a stack, and looking @ elements from the end Having a hashmap { key | val reverse index of input | assoicated english words (ex: "hundred", "thousand") } manually input some logic around index[8:44] a bit cancer, give up | Solution Checking & retrospect[8:44 - 10:52] Eat, Shower, think about this shit, and having brain fart but finally crack it[10:53] Start Coding againProblem Soving: 1. digits rules : name changes every thousands 1,000,000,000 b m t 2. Using divide and conquer to continue breaking large number to smaller instance and have a few base case to handle any numbers smaller than hundreds[11:41] FUCK it, so many edge case... why?'''# dfs: make sure to keep track of parameter passing classSolution(object):
defnumberToWords(self, num):
less_than_20= ["", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen", "Twenty"]
tens= ["", "Ten", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"]
thousands= ["" , "Thousand", "Million", "Billion"]
res=""ifnum==0: return"Zero"foriinrange(len(thousands)):
ifnum%1000!=0:
res=self.dfsHelper(num%1000, less_than_20, tens).strip() +" "+thousands[i] +" "+resnum//=1000returnres.strip()
defdfsHelper(self, num, less_than_20, tens):
ifnum<20:
returnless_than_20[num]
elif20<=num<100:
returntens[num//10] +" "+less_than_20[num%10]
elif100<=num<=999:
returnless_than_20[num//100] +" Hundred "+self.dfsHelper(num%100, less_than_20, tens)
The text was updated successfully, but these errors were encountered:
The text was updated successfully, but these errors were encountered: