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. Zookeeper客户端使用

    参考链接: http://blog.csdn.net/jason5186/article/details/46314381 http://ifeve.com/zookeeper-path-cache/

  2. Web API(三):创建Web API项目

    在本篇文章中将讲解如何使用Visual Studio创建一个新的ASP.NET Web API项目. 在Visual Studio中有两种方式用于创建Web API项目: 1.创建带MVC的Web A ...

  3. CodeIgniter(3.1.4)框架中-使用多个公共控制器

    项目目录结构: 在core/MY_Controller.php文件下: <?php /** * Class MY_Controller * 自定义控制器 */ class MY_Controll ...

  4. d3js把circle和rect连接在一起

    怎么办呢...哎...突然就必须全选中了.... 但是...一不小心想到 在g里面都添加circle和rect 但是根据tpye可以让circle的r为0或者rect的width和height为0,这 ...

  5. 02 Architecture Overview

    本章提要---------------------------------------------arthiecture, and some componentconnect to oracle这一章 ...

  6. ionic2 生命周期

    在 Ionic 2 的版本中生命周期命名的改变,以及各个事件的解释. 官方文档地址在 这里 . 事件名称 事件说明 ionViewLoaded 页面加载完毕触发.该事件发生在页面被创建成 DOM 的时 ...

  7. android EditText设置光标、边框和图标,以及限制输入

    控制边框形状,先在drawable中建一个xml文件:shape.xml <?xml version="1.0" encoding="utf-8"?> ...

  8. Android XmlPullParser 笔记

    使用XmlPullParser解析xml文件. 要解析的xml文件如下所示. weather.xml <?xml version="1.0" encoding="u ...

  9. 关于HTTP keep-alive的实验(转至 http://my.oschina.net/flashsword/blog/80037)

    前面一篇文章提到,HTTP1.1中持久连接已经是默认配置,除非设置Connection为close,否则默认都会进行持久连接.但是我们知道事实标准跟教科书还是可能会有一定差距的,所以不妨自己尝试一下. ...

  10. 【c语言】推断一个数是奇偶数

    // 推断一个数是奇偶数 #include <stdio.h> void judge_sd(int a) { if ((a & 1) == 0) { printf("是偶 ...