12. Integer to Roman

罗马数字

class Solution {
    public String intToRoman(int num) {
        String res = "";
        for(int k=0;k=500){
            res+="D";
            num-=500;
        }
        if(num/100==4){
            res+="CD";
            num-=400;
        }
        for(int k=0;k=50){
            res+="L";
            num-=50;
        }
        if(num/10==4){
            res+="XL";
            num-=40;
        }
        for(int k=0;k=5){
            res+="V";
            num-=5;
        }
        if(num==4){
            res+="IV";
            return res;
        }
        for(int k=0;k

你可能感兴趣的:(12. Integer to Roman)