-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path0504-Base7.cs
33 lines (28 loc) · 837 Bytes
/
0504-Base7.cs
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
//-----------------------------------------------------------------------------
// Runtime: 76ms
// Memory Usage: 23 MB
// Link: https://leetcode.com/submissions/detail/352336254/
//-----------------------------------------------------------------------------
using System.Linq;
using System.Text;
namespace LeetCode
{
public class _0504_Base7
{
public string ConvertToBase7(int num)
{
if (num == 0) return "0";
var signal = num < 0;
if (num < 0) num = -num;
var sb = new StringBuilder();
while (num > 0)
{
sb.Append((num % 7).ToString());
num /= 7;
}
if (signal)
sb.Append('-');
return new string(sb.ToString().Reverse().ToArray());
}
}
}