Integer to Roman
given rules, to some kind of covert stuff.
class Solution {
public String intToRoman(int num) {
int[] decimal = {1000,900,500,400,100,90,50,40,10,9,5,4,1};
String[] roman = {"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"};
StringBuilder res = new StringBuilder();
for (int i = 0; i<decimal.length;i++){
while(num >= decimal[i]){
num = num - decimal[i];
res.append(roman[i]);
}
}
return res.toString();
}
}

浙公网安备 33010602011771号