编程语言:Java
题目链接:https://leetcode-cn.com/problems/integer-to-roman/
题解:水题
难度:Medium
结果:
class Solution {
public String intToRoman(int num) {
int[]a={1000,900,500,400,100,90,50,40,10,9,5,4,1};
String[]b={"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"};
StringBuilder sb=new StringBuilder();
int x=num;
for(int i=0;i<a.length;i++){
int times=x/a[i];
for(int j=0;j<times;j++){
sb.append(b[i]);
}
x%=a[i];
}
return sb.toString();
}
}