273. Integer to English Words
Convert a non-negative integer to its english words representation. Given input is guaranteed to be less than 231- 1.
Example 1:
Input:
123
Output:
"One Hundred Twenty Three"Example 2:
Input:
12345
Output:
"Twelve Thousand Three Hundred Forty Five"Example 3:
Input:
1234567
Output:
"One Million Two Hundred Thirty Four Thousand Five Hundred Sixty Seven"Example 4:
Thoughts: 1. Only limited cases, enumerate all of them out:
Hundred: 100
Thousand: 1,000
Million: 1,000,000
Billion: 1,000,000,000
all the tenth + 1 - 9
Build the string by recursively first processing the dividend, then reminder.
Only write "zero" when input is just '0', else ''
Code:
Code: C++ with trim() implementation
Previous426. Convert Binary Search Tree to Sorted Doubly Linked ListNext157. Read N Characters Given Read4
Last updated
Was this helpful?