Leetcode12--->Integer to Roman(整数转换为罗马数字)
题目: 给定一个整数,将其转换为罗马数字;
题目很简单,主要是依靠整数和罗马数字的对应表:
I= 1;V= 5; X = 10; L = 50; C = 100; D = 500; M = 1000
代码如下:
public class Solution {
public String intToRoman(int num) {
if(num <= 0)
return "";
String[][] RomanDict = new String[][] {
{ "", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX" },
{ "", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC" },
{ "", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM" },
{ "", "M", "MM", "MMM", "", "", "", "", "", "", "" },
}; return RomanDict[3][num / 1000] +
RomanDict[2][num % 1000 / 100] +
RomanDict[1][num % 100 / 10] +
RomanDict[0][num % 10]; }
}
Leetcode12--->Integer to Roman(整数转换为罗马数字)的更多相关文章
- Leetcode12.Integer to Roman整数转罗马数字
罗马数字包含以下七种字符: I, V, X, L,C,D 和 M. 字符 数值 I 1 V 5 X 10 L 50 C 100 D 500 M 1000 例如, 罗马数字 2 写做 II ,即为两个并 ...
- lintcode :Integer to Roman 整数转罗马数字
题目 整数转罗马数字 给定一个整数,将其转换成罗马数字. 返回的结果要求在1-3999的范围内. 样例 4 -> IV 12 -> XII 21 -> XXI 99 -> XC ...
- [LeetCode] 12. Integer to Roman 整数转为罗马数字
Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Value I 1 ...
- 【LeetCode】12. Integer to Roman 整数转罗马数字
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 个人公众号:负雪明烛 本文关键词:roman, 罗马数字,题解,leetcode, 力扣, ...
- 【LeetCode】Integer to Roman(整数转罗马数字)
这道题是LeetCode里的第12道题. 吐了,刚做完"罗马数字转整数",现在又做这个.这个没什么想法,只能想到使用if语句嵌套,或者使用哈希表.但哈希表我还不熟练啊.先拿if嵌套 ...
- [leetcode]12. Integer to Roman整数转罗马数字
Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Value I 1 ...
- [LintCode] Integer to Roman 整数转化成罗马数字
Given an integer, convert it to a roman numeral. The number is guaranteed to be within the range fro ...
- [LeetCode] Integer to Roman 整数转化成罗马数字
Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 t ...
- [LeetCode] 12. Integer to Roman 整数转化成罗马数字
Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Value I 1 ...
随机推荐
- PHPStorm2017.1.3永久激活方法之本地破解激活
是时候升级你的phpstorm了,咱们马上行动! 下载 1.phpstorm https://www.jetbrains.com/phpstorm/download/ 2.破解包 破解补丁无需使用注册 ...
- base-command
命令分类 自带命令 工具型 文件系统 第三方命令 CLI GUI 操作文件系统 pwd(print working directory) ls(list files) ls 列出当前目录文件 ls 目 ...
- jQuery动态追加移除CSS样式
jQuery基础知识,动态添加删除CSS样式 <!DOCTYPE html> <html lang="en"> <head> <meta ...
- Object-C反射读取实体属性和值
举例: 首先定义TestModel如下: @interface TestModel : NSObject @property (nonatomic, strong) NSString *name; @ ...
- Python+selenium整合自动发邮件功能
主要实现的目的是:自动将测试报告以邮件的形式通知相关人员 from HTMLTestRunner import HTMLTestRunner import HTMLTestReport from em ...
- 字符串转换JSON 的方法
function (sJSON) { if (window.JSON) { return window.JSON.parse(sJSON); } else { return eval('(' + sJ ...
- java ArrayList remove
packimport java.util.ArrayList;import java.util.List; public class ArrayListRemove { public static v ...
- Bootstrap历练实例:导航内的下拉菜单
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...
- untiy3d action管理机制的编写
使用unity3d对于一些可视化强迫者来说,是一个不错的选择,但unity3d没有cocos2d的action管理机制,比如cocos2dx的CCMoveTo,CCScale等action,所以笔者通 ...
- Python爬虫系列-Requests库详解
Requests基于urllib,比urllib更加方便,可以节约我们大量的工作,完全满足HTTP测试需求. 实例引入 import requests response = requests.get( ...