mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-10 00:09:06 +01:00
problems(rs): add “258. Add Digits”
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
0d66103a07
commit
ae2082c39c
1 changed files with 13 additions and 0 deletions
13
problems/add-digits.rs
Normal file
13
problems/add-digits.rs
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
impl Solution {
|
||||||
|
pub fn add_digits(num: i32) -> i32 {
|
||||||
|
if num == 0 {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if num % 9 == 0 {
|
||||||
|
return 9;
|
||||||
|
}
|
||||||
|
|
||||||
|
num % 9
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue