-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntegerToRoman.java
More file actions
38 lines (32 loc) · 1.06 KB
/
IntegerToRoman.java
File metadata and controls
38 lines (32 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<<<<<<< HEAD
//12. Integer to Roman
class Solution {
public String intToRoman(int num) {
int[] value = {1000,900,500,400,100,90,50,40,10,9,5,4,1};
String[] symbol = {"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"};
StringBuilder roman = new StringBuilder();
for(int i=0;i<13 && num>0;i++){
while(num >= value[i]){
roman.append(symbol[i]);
num -= value[i];
}
}
return roman.toString();
}
=======
//12. Integer to Roman
class Solution {
public String intToRoman(int num) {
int[] value = {1000,900,500,400,100,90,50,40,10,9,5,4,1};
String[] symbol = {"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"};
StringBuilder roman = new StringBuilder();
for(int i=0;i<13 && num>0;i++){
while(num >= value[i]){
roman.append(symbol[i]);
num -= value[i];
}
}
return roman.toString();
}
>>>>>>> be6ce0b427078b1421d5dd74adb2300dc02daeec
}