题目:对应之前那道将罗马数字转换整型数字的题目。反过来。

思路:刚开始做的时候,想着用程序进行判断,复杂的要死。网络了别人代码,非常清晰。

代码:

 1    public String intToRoman(int num) {
String[] alpha = {"M" ,"CM" , "D" , "CD" , "C" ,"XC" , "L" , "XL" , "X" ,"IX" , "V" , "IV" , "I"};
int[] value = new int[]{1000 ,900 , 500 , 400 , 100 , 90 , 50 , 40 ,10 , 9 , 5 , 4 , 1};
String result = new String();
for(int i = 0 ; num != 0 ; i++){
while(num >= value[i]){
num -= value[i];
result += alpha[i];
}
}
return result;
}

贪心的思路,直接AC,very nice~

[leetcode]_Integer to Roman的更多相关文章

  1. leetcode第一刷_Integer to Roman

    这道题当时不会写,是參照discuss写的. 首先要弄明确罗马数字的规则,这个在国外难道是常识吗.为什么题干一点都没讲.. 4000以下一共同拥有以下几种符号:"M", " ...

  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】#13. Roman to Integer

    一天一道LeetCode系列 (一)题目 Given a roman numeral, convert it to an integer. Input is guaranteed to be with ...

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

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

  5. LeetCode题解(13)--Roman to Integer

    https://leetcode.com/problems/roman-to-integer/ 原题: Given a roman numeral, convert it to an integer. ...

  6. Leetcode Integer to Roman

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

  7. 【LeetCode】13. Roman to Integer 罗马数字转整数

    题目: Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from ...

  8. 【leetcode】13. Roman to Integer

    题目描述: Given a roman numeral, convert it to an integer. 解题分析: 这道题只要百度一下转换的规则,然后着这解释写代码即可.实现上并没有什么难度,直 ...

  9. 【算法】LeetCode算法题-Roman To Integer

    这是悦乐书的第145次更新,第147篇原创 今天这道题和罗马数字有关,罗马数字也是可以表示整数的,如"I"表示数字1,"IV"表示数字4,下面这道题目就和罗马数 ...

随机推荐

  1. 20145305 《Java程序设计》第6周学习总结

    教材学习内容总结 1.输入串流代表对象为java.io.InputStream实例,输出串流代表对象为java.io.OutputStream实例 2.InputStream与OutputStream ...

  2. C++学习33 函数模板

    在<C++函数重载>一节中,为了求三个数的最大值,我们通过函数重载定义了三个名字相同.参数列表不同的函数,如下所示: //求三个整数的最大值 int max(int a, int b, i ...

  3. Java SE 第十一讲----面向对象特征之封装2

    1.如果一个类包含了属性跟方法,那么该类的每一个对象都具有自己的属性,但无乱一个类有多少个对象,这些对象共享同一个方法. 2.关于方法参数传递的总结: 对于Java中的方法参数传递,无论传递的是原生数 ...

  4. Asp.Net 上传图片并生成高清晰缩略图(转)

    在asp.net中,上传图片功能或者是常用的,生成缩略图也是常用的.baidu或者google,c#的方法也是很多的,但是一用却发现缩略图不清晰啊,缩略图片太大之类的事情,下面是我在处理图片上的代码, ...

  5. IIS报错,App_global.asax.×××.dll拒绝访问

    解决方案: ①找到C:\Windows下的temp文件夹 ②属性->安全->编辑->添加IIS_IUSERS,给其添加上可读写的权限,然后应用,确定即可

  6. cocos2d-lua 3.5 ios搭建步骤

    xcode搭建cocos2d-lua是最简单的,不用 配置一系列环境变量,只把xcode安装好就可以 步骤一:去官网下载quick-3.5,然后打开命令行工具 步骤二:cd进入/Users/song/ ...

  7. Virtualenv介绍

    [翻译]http://virtualenv.readthedocs.org/en/latest/index.html virtualenv是创建独立python环境的一种工具. 环境搭建的过程中,有一 ...

  8. Android开发-API指南-<activity-alias>

    <activity-alias> 英文原文:http://developer.android.com/guide/topics/manifest/activity-alias-elemen ...

  9. deep learning新征程

    deep learning新征程(一) zoerywzhou@gmail.com http://www.cnblogs.com/swje/ 作者:Zhouwan  2015-11-26   声明: 1 ...

  10. Node.js log4js日志记录

    这次需要给之前弄的文件服务器添加日志记录,一般每天产生的日志会特别多所以安装日期来划分是最好的,这里我用了express框架,为了适应express框架这里在log.js文件中写了use方法. //日 ...