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 3ef46c0 commit a33c203Copy full SHA for a33c203
solution/0000-0099/0012.Integer to Roman/README.md
@@ -302,25 +302,26 @@ class Solution {
302
303
#### C
304
305
-```C
306
-
307
-char *intToRoman(int num) {
308
- static char res[20];
309
- res[0] = '\0';
310
311
- int vals[] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
312
- char *syms[] = {"M", "CM", "D", "CD", "C", "XC", "L",
313
- "XL", "X", "IX", "V", "IV", "I"};
314
315
- for (int i = 0; i < 13; i++) {
316
- while (num >= vals[i]) {
317
- strcat(res, syms[i]);
318
- num -= vals[i];
+```c
+static const char* cs[] = {
+ "M", "CM", "D", "CD", "C", "XC",
+ "L", "XL", "X", "IX", "V", "IV", "I"};
+
+static const int vs[] = {
+ 1000, 900, 500, 400, 100, 90,
+ 50, 40, 10, 9, 5, 4, 1};
+char* intToRoman(int num) {
+ static char ans[20];
+ ans[0] = '\0';
+ for (int i = 0; i < 13; ++i) {
+ while (num >= vs[i]) {
319
+ num -= vs[i];
320
+ strcat(ans, cs[i]);
321
+ }
322
}
- }
- return res;
323
+ return ans;
324
325
```
326
327
<!-- tabs:end -->
0 commit comments