Skip to content

Commit 33660d7

Browse files
Added interger to roman leetcode problem
1 parent 789afc5 commit 33660d7

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed
File renamed without changes.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public:
3+
string intToRoman(int num) {
4+
int value[]={1,4,5,9,10,40,50,90,100,400,500,900,1000};
5+
string symbol []={"I","IV","V","IX","X","XL","L","XC","C","CD","D","CM","M"};
6+
string ans="";
7+
for(int i=12;i>=0;i--){
8+
int x=value[i];
9+
int mul=num/x;
10+
while(mul){
11+
ans.append(symbol[i]);
12+
mul--;
13+
}
14+
num=num%x;
15+
}
16+
return ans;
17+
}
18+
};

0 commit comments

Comments
 (0)