Discover Packages
github.com/openset/leetcode
problems
add-digits
package
Version:
v1.5.1
Opens a new window with list of versions in this module.
Published: Dec 8, 2019
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 a non-negative integer num
, repeatedly add all its digits until the result has only one digit.
Example:
Input: 38
Output: 2
Explanation: The process is like: 3 + 8 = 11
, 1 + 1 = 2
.
Since 2
has only one digit, return it.
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.