• https://leetcode-cn.com/problems/roman-to-integer/submissions/


    package oj;

    import java.util.HashMap;
    import java.util.Map;

    public class RomanToInteger0816 {
    Map<Character, Integer> characterIntegerHashMap = new HashMap() {
    {
    put('I', 1);
    put('V', 5);
    put('X', 10);
    put('L', 50);
    put('C', 100);
    put('D', 500);
    put('M', 1000);
    }};

    public int romanToInt(String s) {
    int len = s.length();
    int ans = 0;
    for (int i = 0; i < len; i++) {
    int value = characterIntegerHashMap.get(s.charAt(i));
    if (i < len - 1 && (value < characterIntegerHashMap.get(s.charAt(i + 1)))) {
    ans -= value;
    } else {
    ans += value;
    }
    }
    return ans;
    }

    public static void main(String[] args) {
    RomanToInteger0816 romanToInteger0816 = new RomanToInteger0816();
    System.out.println(romanToInteger0816.romanToInt("IX"));
    }
    }
  • 相关阅读:
    PHP array_intersect_uassoc
    PHP array_intersect_key
    PHP array_intersect_assoc
    PHP array_flip
    PHP array_filter
    PHP array_fill
    PHP array_fill_keys
    Android4.0-Fragment框架实现方式剖析
    Fragment 生命周期
    WebView
  • 原文地址:https://www.cnblogs.com/yangnk/p/15150476.html
Copyright © 2020-2023  润新知