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