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/013_Roman_to_Integer.java at master · ChenGavi/leetcode Expand file tree/ Copy path013_Roman_to_Integer.javaMore file actions 23 lines (20 loc) · 529 Bytes / Copy path013_Roman_to_Integer.javaFile metadata and controls23 lines (20 loc) · 529 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 int romanToInt(String s) { int[] arr = new int['A' + 26]; arr['I'] = 1; arr['V'] = 5; arr['X'] = 10; arr['L'] = 50; arr['C'] = 100; arr['D'] = 500; arr['M'] = 1000; int result = 0; int prev = 0; for (int i = s.length() - 1; i >= 0; i--) { int current = arr[s.charAt(i)]; result += prev > current ? -current : current; prev = current; } return result; } } |
| 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. |