my java solution


  • 0
    C
    public class Solution {
    public String intToRoman(int num) {
        int [] nums = new int []{1000,900,500,400,100,90,50,40,10,9,5,4,1};
        String [] terms = new String[] {"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"};
        
        StringBuffer sb = new StringBuffer();
        for(int i=0;i<nums.length;i++)
        {   
            Integer current = nums[i];
            while(num >= current)
            {
                num-=current;
                sb.append(terms[i]);
            }
        }
        
        return sb.toString();
    }
    

    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.