Java [leetcode 12] Integer to Roman
题目描述:
Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
解题思路:
这道题没什么技术含量,一个一个除10以及取模运算就行。
代码如下:
public class Solution {
public String intToRoman(int num) {
String Roman[][] = {
{"", "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"}
};
int remainder;
int carry = num;
int index = 0;
String result = new String();
while(carry != 0){
remainder = carry % 10;
result = Roman[index][remainder] + result;
index++;
carry = carry / 10;
}
return result;
}
}
Java [leetcode 12] Integer to Roman的更多相关文章
- Leetcode 12——Integer to Roman
12.Integer to Roman Given an integer, convert it to a roman numeral. Input is guaranteed to be withi ...
- Leetcode 12. Integer to Roman(打表,水)
12. Integer to Roman Medium Roman numerals are represented by seven different symbols: I, V, X, L, C ...
- [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 整数转为罗马数字
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 ☆☆
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 ...
- LeetCode——12. Integer to Roman
一.题目链接:https://leetcode.com/problems/integer-to-roman/ 二.题目大意: 给定一个整数,返回它的罗马数字的形式. 三.题解: 要想做出这道题目,首先 ...
- LeetCode 12 Integer to Roman (整数转罗马数字)
题目链接: https://leetcode.com/problems/integer-to-roman/?tab=Description String M[] = {"", ...
- [leetcode] 12. Integer to Roman
关于罗马数字: I: 1V: 5X: 10L: 50C: 100D: 500M: 1000字母可以重复,但不超过三次,当需要超过三次时,用与下一位的组合表示:I: 1, II: 2, III: 3, ...
随机推荐
- 1020. Tree Traversals (序列建树)
Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and i ...
- js 使用技巧 - [近几年工作中的经验总结的技巧]
1.如果 ajax 返回单一的 json 格式,接收方需要这样再格式化一下赋值: var str = eval("(" + msg + ")"); 开发引用: ...
- VS2010中无法嵌入互操作类型“......”,请改用适用的接口的解决方法
- EXTJS 4.2 资料 控件textfield中fieldLabel去掉冒号,控件label的长度
代码: labelSeparator: '', // 去掉laebl中的冒号 labelWidth: 10,//控件label的长度
- jq 7种实例化
$(html) ->$(array) $(html,{}||$(...)) $(#id) $(expr,$(...)) $(expr,context) $(dom) $(function(){} ...
- 1028: [JSOI2007]麻将 - BZOJ
Description 麻将是中国传统的娱乐工具之一.麻将牌的牌可以分为字牌(共有东.南.西.北.中.发.白七种)和序数牌(分为条子.饼子.万子三种花色,每种花色各有一到九的九种牌),每种牌各四张.在 ...
- SQL注入中的WAF绕过技术
目录 1.大小写绕过 2.简单编码绕过 3.注释绕过 4.分隔重写绕过 5.Http参数污染(HPP) 6.使用逻辑运算符 or /and绕过 7.比较操作符替换 8.同功能函数替换 9.盲注无需or ...
- hdu 1018
数学题 用的这个方法比较烂 g++超时 c++ 406ms /******************************************************************* ...
- hdu 3682
将每个格子标记为 x*n*n+y*n+z 每个格子会有一个独特的编号 将它放入vector中 去重 我一开始用 set 超时 #include <cstdio> #include ...
- Mesh Baker的基本操作与功能演示
原地址:http://www.narkii.com/club/thread-301789-1.html 如何降低游戏在系统中的消耗并带给用户最佳的体验是开发者一直追求的目标,在Unity里面对于模型与 ...