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/src/RomanToInteger.java at master · LeBW/leetcode Expand file tree/ Copy pathRomanToInteger.javaMore file actions 28 lines (27 loc) · 812 Bytes / Copy pathRomanToInteger.javaFile metadata and controls28 lines (27 loc) · 812 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 /** * @author LBW */ public class RomanToInteger { public int romanToInt(String s) { int result = 0; int[] nums = new int[]{1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1}; String[] dict = new String[]{"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"}; int index = 0; while (!s.equals("")) { int targetSize = dict[index].length(); if (s.length() < targetSize) { index++; continue; } String target = s.substring(0, targetSize); if (target.equals(dict[index])) { s = s.substring(targetSize); result += nums[index]; } else { index++; } } return result; } } |
| You are visitor 01402775 — 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. |