Skip to content

Commit 1cb4199

Browse files
authored
Create 12. Integer to Roman
1 parent e2daf9a commit 1cb4199

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

12. Integer to Roman

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

0 commit comments

Comments
 (0)