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();
    }
}
posted @ 2020-09-07 11:20  EvanMeetTheWorld  阅读(19)  评论(0)    收藏  举报