Nav: << previous: 272.最接近的二叉搜索树值 II | next: 274.H 指数 >>


Description

tab: English
 
<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>
 
 
 
> [!tip]- Hint 1
> 
> Did you see a pattern in dividing the number into chunk of words? For example, 123 and 123000.
 
> [!tip]- Hint 2
> 
> Group the number by thousands (3 digits). You can write a helper function that takes a number less than 1000 and convert just that chunk to words.
 
> [!tip]- Hint 3
> 
> There are many edge cases. What are some good test cases? Does your code work with input such as 0? Or 1000010? (middle chunk is zero and should not be printed out)
 
 
---
 
[submissions](https://leetcode.com/problems/integer-to-english-words/submissions/) | [solutions](https://leetcode.com/problems/integer-to-english-words/solutions/)
 
 
tab: 中文
 
<p>将非负整数 <code>num</code> 转换为其对应的英文表示。</p>
 
<p>&nbsp;</p>
 
<p><strong>示例 1:</strong></p>
 
<pre>
<strong>输入:</strong>num = 123
<strong>输出:</strong>"One Hundred Twenty Three"
</pre>
 
<p><strong>示例 2:</strong></p>
 
<pre>
<strong>输入:</strong>num = 12345
<strong>输出:</strong>"Twelve Thousand Three Hundred Forty Five"
</pre>
 
<p><strong>示例 3:</strong></p>
 
<pre>
<strong>输入:</strong>num = 1234567
<strong>输出:</strong>"One Million Two Hundred Thirty Four Thousand Five Hundred Sixty Seven"
</pre>
 
<p>&nbsp;</p>
 
<p><strong>提示:</strong></p>
 
<ul>
	<li><code>0 &lt;= num &lt;= 2<sup>31</sup> - 1</code></li>
</ul>
 
 
 
> [!tip]- 提示 1
> 
> Did you see a pattern in dividing the number into chunk of words? For example, 123 and 123000.
 
> [!tip]- 提示 2
> 
> Group the number by thousands (3 digits). You can write a helper function that takes a number less than 1000 and convert just that chunk to words.
 
> [!tip]- 提示 3
> 
> There are many edge cases. What are some good test cases? Does your code work with input such as 0? Or 1000010? (middle chunk is zero and should not be printed out)
 
 
---
 
[提交记录](https://leetcode.cn/problems/integer-to-english-words/submissions/) | [题解](https://leetcode.cn/problems/integer-to-english-words/solution/)
 
 

Solutions & Notes

properties:
  note.updated:
    displayName: Last Updated
  note.relative_links:
    displayName: Related Links
  note.desc:
    displayName: Description
  note.grade:
    displayName: Rating
  note.program_language:
    displayName: Language
  note.time_complexity:
    displayName: TC
  note.space_complexity:
    displayName: SC
views:
  - type: table
    name: Solutions & Notes
    filters:
      and:
        - file.hasLink(this.file)
        - file.tags.containsAny("leetcode/solution", "leetcode/note")
    order:
      - file.name
      - desc
      - program_language
      - time_complexity
      - space_complexity
      - grade
      - relative_links
      - updated
    sort:
      - property: grade
        direction: ASC
      - property: time_complexity
        direction: ASC
      - property: program_language
        direction: ASC
    columnSize:
      file.name: 104
      note.space_complexity: 65
      note.grade: 126
 

Similar Problems

properties:
  note.lcTopics:
    displayName: Topics
  note.lcAcRate:
    displayName: AC Rate
  note.favorites:
    displayName: Favorites
  note.grade:
    displayName: Rating
  note.translatedTitle:
    displayName: Title (CN)
  note.lcDifficulty:
    displayName: Difficulty
views:
  - type: table
    name: Similar Problems
    filters:
      and:
        - file.hasLink(this.file)
        - similarQuestions.contains(this.file)
    order:
      - file.name
      - translatedTitle
      - lcTopics
      - lcDifficulty
      - lcAcRate
      - grade
      - favorites
    sort:
      - property: file.name
        direction: ASC
      - property: lcTopics
        direction: DESC
    columnSize:
      note.translatedTitle: 240
      note.lcTopics: 347
      note.lcAcRate: 75
      note.grade: 122