今天做了Leetcode的一个简单的罗马数字转整数的题目,觉得应该把我的思路写下来。才疏学浅,如有更好的算法望不吝赐教。
/** * 首先将字符串转为字符数组,其次遍历数组,采用switch语句来选择 * 判断罗马数字的六种特殊情况 * 返回结果 */ public class test { public static int Romantoint(String s){ int result=0; char[] chars= s.toCharArray(); for (int i=0;i<chars.length;i++){