Description:

Given an integer, convert it to a roman numeral.

Input is guaranteed to be within the range from 1 to 3999.

noting to say.

public class Solution {

    public String intToRoman(int number) {

        int[] values = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 };
String[] numerals = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I" };
StringBuilder result = new StringBuilder();
for (int i = 0; i < values.length; i++) {
while (number >= values[i]) {
number -= values[i];
result.append(numerals[i]);
}
}
return result.toString();
}
}

LeetCode——Integer to Roman的更多相关文章

  1. LeetCode: Integer to Roman 解题报告

    Integer to Roman Given an integer, convert it to a roman numeral. Input is guaranteed to be within t ...

  2. [LeetCode] Integer to Roman 整数转化成罗马数字

    Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 t ...

  3. Leetcode Integer to Roman

    Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 t ...

  4. leetcode Integer to Roman python

    class Solution(object): def intToRoman(self, num): """ :type num: int :rtype: str &qu ...

  5. [LeetCode][Python]Integer to Roman

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/integer ...

  6. Integer to Roman - LeetCode

    目录 题目链接 注意点 解法 小结 题目链接 Integer to Roman - LeetCode 注意点 考虑输入为0的情况 解法 解法一:从大到小考虑1000,900,500,400,100,9 ...

  7. LeetCode OJ:Integer to Roman(转换整数到罗马字符)

    Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 t ...

  8. LeetCode:12. Roman to Integer (Easy)

    1. 原题链接 https://leetcode.com/problems/roman-to-integer/description/ 2. 题目要求 (1)将罗马数字转换成整数:(2)范围1-399 ...

  9. leetCode练题——12. Integer to Roman

    1.题目 12. Integer to Roman Roman numerals are represented by seven different symbols: I, V, X, L, C,  ...

随机推荐

  1. Web API(二):Web API概述

    一.什么是API API(Application Programming Interface)即应用程序编程接口,是一些预先定义的函数,目的是提供应用程序与开发人员基于某软件或硬件得以访问一组例程的能 ...

  2. jQuery实现布局高宽自适应

    在页面布局(layout)时经常是上左右的框架布局并且需要宽.高度的自适应,div+css是无法实现(*hegz:div+css其实是可以实现的,利用jQuery比较容易实现浏览器的兼容性),所以需要 ...

  3. loadrunner -56992

    设置Run-time Settings ,network speed ,use bandwidth为 512: 回放脚本没有报错,5个并发运行场景报如下错误: vuser_init.c(12): Er ...

  4. Java的四种引用类型之弱引用

    先说结论: 首先,Java中有四种引用类型:强引用.软引用.弱引用.虚引用.-- 在 Java 1.2 中添加的,见 package java.lang.ref; . 其次,这几个概念是与垃圾回收有关 ...

  5. Spring Annotation是怎么工作的?

    最近刚好看了下注解,虽然明白了注解的作用原理,但是仍然不明白Spring中的注解是如何工作的. 占座用,留待后续. 先来两个链接吧 https://dzone.com/articles/spring- ...

  6. 第二百九十五节,python操作redis缓存-字符串类型

    python操作redis缓存-字符串类型 首先要安装redis-py模块 python连接redis方式,有两种连接方式,一种是直接连接,一张是通过连接池连接 注意:以后我们都用的连接池方式连接,直 ...

  7. e672. 缩放,剪取,移动,翻转缓冲图像

    AffineTransform tx = new AffineTransform(); tx.scale(scalex, scaley); tx.shear(shiftx, shifty); tx.t ...

  8. 配置 -- PHPstorm+Xdebug断点调试PHP

    运行环境: PHPSTORM版本 : 8.0.1 PHP版本 : 5.6.2 xdebug版本:php_xdebug-2.2.5-5.6-vc11-x86_64.dll ps : php版本和xdeb ...

  9. bootstrap -- css -- 文字、列表

    文字 <small></small>:呈现小号字体效果. <big></big>:程序大号字体效果 <abbr></abbr>: ...

  10. 转载:【原译】Erlang构建和匹配二进制数据(Efficiency Guide)

    转自:http://www.cnblogs.com/futuredo/archive/2012/10/19/2727204.html Constructing and matching binarie ...