(表盘上的四点钟“IIII”例外) 在一个数的上面画一条横线,表示这个数扩大1000倍。 1publicclassSolution {2publicString intToRoman(intnum) {3String [] I = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"};4String [] X = {"", "X", "X
Explanation: M = 1000, CM = 900, XC = 90 and IV = 4. classSolution {publicString intToRoman(intnum) {intlen; String str="";int[] val = {1000,500,100,50,10,5,1};char[] sym = {'M','D','C','L','X','V','I'};for(inti = 0; i < val.length; i+=2){ len= n...
* Given an integer, convert it to a roman numeral. * * Input is guaranteed to be within the range from 1 to 3999. * * Created by fuxuemingzhu on 2015/9/4. */ public class Solution { static int value[] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1}; ...
public class Solution { public int romanToInt(String s) { int total = charToInt(s.charAt(0)); for(int i = 1; i < s.length(); i++){ int prev = charToInt(s.charAt(i-1)); int curr = charToInt(s.charAt(i)); if(curr <= prev){ total += curr; } else { total = tot...
package javaLeetCode.primary; import java.util.HashMap; import java.util.Map; import java.util.Scanner; import java.util.Stack; public class RomanToInteger_13 { public static void main(String[] args) { System.out.println("Please input a roman numeral:"); ...
https://leetcode.com/problems/integer-to-roman/discuss/6310/My-java-solution-easy-to-understand publicStringintToRoman(intnum){int[]values={1000,900,500,400,100,90,50,40,10,9,5,4,1};String[]strs={"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"};Stri...
https://leetcode.com/problems/roman-to-integer/discuss/6509/7ms-solution-in-Java.-easy-to-understand 利用到罗马数字的规则,一般情况是表示数字大的字母在前,数字小的字母在后,如果不是这样,就说明出现了特殊情况,此时应该做减法。 privateintgetVal(charc){switch(c){case'M':return1000;case'D':return...
Java publicclassSolution {publicintromanToInt(String s) {if(s==null|| s.length()==0)return0; Map<Character,Integer> m =newHashMap<Character,Integer>(); m.put('I',1); m.put('V',5); m.put('X',10); m.put('L',50); ...
问Integer to Roman“不兼容的类型: int无法转换为布尔型[在MainClass.java中]”EN根据罗马数字的规则...
classSolution {publicString intToRoman(intnum) {intlen; String str="";int[] val = {1000,500,100,50,10,5,1};char[] sym = {'M','D','C','L','X','V','I'};for(inti = 0; i < val.length; i+=2){ len= num/val[i];if(len <=3 ){//0-3for(intj = 0; j < len...