-
Notifications
You must be signed in to change notification settings - Fork 135
Expand file tree
/
Copy path1271-Hexspeak.cs
More file actions
33 lines (26 loc) · 832 Bytes
/
1271-Hexspeak.cs
File metadata and controls
33 lines (26 loc) · 832 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
//-----------------------------------------------------------------------------
// Runtime: 84ms
// Memory Usage: 24.4 MB
// Link: https://leetcode.com/submissions/detail/343614888/
//-----------------------------------------------------------------------------
using System.Text;
namespace LeetCode
{
public class _1271_Hexspeak
{
public string alphabet = "OI23456789ABCDEF";
public string ToHexspeak(string num)
{
var number = long.Parse(num);
var sb = new StringBuilder();
while (number > 0)
{
var curr = (int)(number % 16);
if (curr > 1 && curr < 10) return "ERROR";
sb.Insert(0, alphabet[curr]);
number /= 16;
}
return sb.ToString();
}
}
}