012_LeetCode_12 Integer to Roman 题解
来源:互联网 发布:电极式暖手宝 知乎 编辑:程序博客网 时间:2024/06/05 20:31
Description
Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
将一个整数转换成罗马数字。
tips:
罗马数字表示如下:1 -> I, 5 -> V, 10 -> X, 50 -> L, 100 -> C, 500 -> D, 1000 -> M.
解:
数字最大不到4000,直接打表,岂不是。。。。。。。。。。。。。。
java代码:
class Solution { public String intToRoman(int num) { String M[] = {"", "M", "MM", "MMM"}; String C[] = {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"}; String X[] = {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"}; String I[] = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"}; return M[num/1000] + C[(num%1000)/100]+ X[(num%100)/10] + I[num%10]; }}
阅读全文
0 0
- 012_LeetCode_12 Integer to Roman 题解
- LeetCode题解:Roman to Integer
- LeetCode题解:Integer to Roman
- LeetCode题解:Roman to Integer
- LeetCode题解:Integer to Roman
- 012 - Integer to Roman
- LeetCode 题解(58): Integer to Roman
- LeetCode 题解(73): Roman to Integer
- leetcode题解||Integer to Roman问题
- leetcode题解 || Roman to Integer问题
- LeetCode题解——Roman to Integer
- LeetCode题解——Integer to Roman
- LEEDCODE 12 Integer to Roman (JAVA题解)
- LEEDCODE 13 Roman to Integer (JAVA题解)
- LeetCodet题解--12. Integer to Roman
- LeetCodet题解--13. Roman to Integer
- LeetCode 12 Integer to Roman题解
- LeetCode题解-12-Integer to Roman
- 171201—备忘录
- Servlet学习笔记(一)
- 2.add two sum
- NOIP2002过河卒
- STM32定时器学习---基本定时器
- 012_LeetCode_12 Integer to Roman 题解
- 51nod 1639 绑鞋带(递推)
- Mongo更新数组$slice修饰符
- dll动态链接库文件编写
- 疯狂输出⚔Java中查表法的使用
- C++中string.find()函数与string::npos
- 深入理解Basic Paxos协议
- JackSon反序列化报错,Unrecognized field, not marked as ignorable
- AtCoder Regular Contest 085 F NRE 线段树优化dp