Skip to content

Commit 73c8a1b

Browse files
authored
int to roman
1 parent f289d32 commit 73c8a1b

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

intToRoman.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public String intToRoman(int num) {
3+
StringBuilder sb = new StringBuilder();
4+
int[] integer = {1000,900,500,400,100,90,50,40,10,9,5,4,1};
5+
String[] roman = {"M", "CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"};
6+
7+
for(int i = 0; i<integer.length; i++){
8+
while(num >= integer[i]){
9+
sb.append(roman[i]);
10+
num -= integer[i];
11+
}
12+
}
13+
return sb.toString();
14+
}
15+
}

0 commit comments

Comments
 (0)