Please laugh at me


  • 3
    B
    public class Solution {
        public String intToRoman(int num) {
            StringBuffer res = new StringBuffer();
            while(num >= 1000){
                res.append("M");
                num -= 1000;
            }
            int temp = num / 100;
            switch(temp){
                case 9: res.append("CM"); break;
                case 8: res.append("DCCC"); break;
                case 7: res.append("DCC"); break;
                case 6: res.append("DC"); break;
                case 5: res.append("D"); break;
                case 4: res.append("CD"); break;
                case 3: res.append("CCC"); break;
                case 2: res.append("CC"); break;
                case 1: res.append("C"); break;
                case 0: break;
            }
            num -= temp*100;
            temp = num / 10;
            switch(temp){
                case 9: res.append("XC"); break;
                case 8: res.append("LXXX"); break;
                case 7: res.append("LXX"); break;
                case 6: res.append("LX"); break;
                case 5: res.append("L"); break;
                case 4: res.append("XL"); break;
                case 3: res.append("XXX"); break;
                case 2: res.append("XX"); break;
                case 1: res.append("X"); break;
                case 0: break;
            }
            num -= temp*10;
            switch(num){
                case 9: res.append("IX"); break;
                case 8: res.append("VIII"); break;
                case 7: res.append("VII"); break;
                case 6: res.append("VI"); break;
                case 5: res.append("V"); break;
                case 4: res.append("IV"); break;
                case 3: res.append("III"); break;
                case 2: res.append("II"); break;
                case 1: res.append("I"); break;
                case 0: break;
            }
            
            return res.toString();
        }
    }
    

  • 0
    2

    哈哈哈哈哈哈哈哈哈哈哈哈哈哈


  • 1
    E

    哈哈哈 好想法 感觉比我的好呢


  • 0
    G

    @bts25305016 没毛病!


  • 0
    F

    I fu le u.

    It's simple and clear


Log in to reply
 

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