926. Convert Digits/Numbers to Words

You are given a non-negative integer num with at most 4 digits (0 <= num <= 9999). Your task is to convert this number into its English words representation.

Example 1:

Input: num = 7824

Output: "seven thousand eight hundred twenty four"

Explanation: 7824 is read as "seven thousand eight hundred twenty four"

Example 2:

Input: num = 370

Output: "three hundred seventy"

Explanation: 370 is read as "three hundred seventy"

Now Your Turn!

Pick the correct output for the given input

Input: num = 1001

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 0 <= num <= 9999
  • Do not include "and" between words (e.g., write "one hundred one", not "one hundred and one")
  • The output should be all lowercase with single spaces between words

Fun Facts

0
class Solution {
public:
string numberToWords(int num) {
// Your code goes here
}
};
Test Case

Input:

Num