Discover Packages
github.com/openset/leetcode
problems
add-digits
package
Version:
v1.6.5
Opens a new window with list of versions in this module.
Published: Mar 23, 2021
License: MIT
Opens a new window with license information.
Imports: 0
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
README
README
¶
< Previous
Next >
Given an integer num
, repeatedly add all its digits until the result has only one digit, and return it.
Example 1:
Input: num = 38
Output: 2
Explanation: The process is
38 --> 3 + 8 --> 11
11 --> 1 + 1 --> 2
Since 2 has only one digit, return it.
Example 2:
Input: num = 0
Output: 0
Constraints:
Follow up: Could you do it without any loop/recursion in O(1)
runtime?
[Math ]
Similar Questions
Happy Number (Easy)
Sum of Digits in the Minimum Number (Easy)
Hints
Hint 1
A naive implementation of the above process is trivial. Could you come up with other methods?
Hint 2
What are all the possible results?
Hint 3
How do they occur, periodically or randomly?
Hint 4
You may find this Wikipedia article useful.
Expand ▾
Collapse ▴
Documentation
¶
There is no documentation for this package.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.