-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0258-Add-digits.cs
More file actions
47 lines (41 loc) · 1005 Bytes
/
0258-Add-digits.cs
File metadata and controls
47 lines (41 loc) · 1005 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using System.Collections.Generic;
using System.Text;
namespace Solution._0258.Add_digits
{
public class _0258_Add_digits
{
/// <summary>
/// Solution 2
/// </summary>
/// <param name="num"></param>
/// <returns></returns>
public int AddDigits(int num)
{
if (num < 10) return num;
if (num % 9 == 0) return 9;
return num % 9;
}
/// <summary>
/// Solution 1
/// </summary>
/// <param name="num"></param>
/// <returns></returns>
//public int AddDigits(int num)
//{
// while (num > 9)
// num = Add(num);
// return num;
//}
//private int Add(int num)
//{
// int result = 0;
// while (num > 0)
// {
// result += num % 10;
// num /= 10;
// }
// return result;
//}
}
}