We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f4f5820 commit 5ca7673Copy full SHA for 5ca7673
C++/hexspeak.cpp
@@ -22,3 +22,28 @@ class Solution {
22
return result;
23
}
24
};
25
+
26
27
+// Time: O(n)
28
+// Space: O(n)
29
+class Solution2 {
30
+public:
31
+ string toHexspeak(string num) {
32
+ uint64_t n = stoul(num);
33
+ stringstream ss;
34
+ ss << hex << uppercase << n;
35
+ string result(ss.str());
36
+ for (auto i = 0; i < result.length(); ++i) {
37
+ if ('2' <= result[i] && result[i] <= '9') {
38
+ return "ERROR";
39
+ }
40
+ if (result[i] == '0') {
41
+ result[i] = 'O';
42
43
+ if (result[i] == '1') {
44
+ result[i] = 'I';
45
46
47
+ return result;
48
49
+};
0 commit comments