GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — leetcode/java/012_Integer_to_Roman.java at master · shangaro/leetcode Expand file tree/ Copy path012_Integer_to_Roman.javaMore file actions 23 lines (19 loc) · 648 Bytes / Copy path012_Integer_to_Roman.javaFile metadata and controls23 lines (19 loc) · 648 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 class Solution { public String intToRoman(int num) { Map<Integer, String> map = new HashMap(); map.put(1, "I"); map.put(5, "V"); map.put(10, "X"); map.put(50, "L"); map.put(100, "C"); map.put(500, "D"); map.put(1000, "M"); map.put(4, "IV"); map.put(9, "IX"); map.put(40, "XL"); map.put(90, "XC"); map.put(400, "CD"); map.put(900, "CM"); int[] sequence = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1}; StringBuffer sb = new StringBuffer(); for (int i = 0; i<sequence.length; i++) { int base = sequence[i]; while (num >= base) { sb.append(map.get(base)); num -= base; } } return sb.toString(); } } |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |