leetcode-12. Integer to Roman(整数转换成罗马数字)
来源:互联网 发布:下载美化照片软件 编辑:程序博客网 时间:2024/06/05 08:54
https://leetcode.com/problems/integer-to-roman/#/description
思路解析:
【罗马数字】1~9: {"I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"};10~90: {"X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"};100~900: {"C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"};1000~3000: {"M", "MM", "MMM"}.
代码如下:
public class Solution { public String intToRoman(int num) { String result=""; 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 d=0; while(num!=0) { int temp=num%10; result=roman[d][temp]+result; d++; num/=10; } return result; }}
阅读全文
0 0
- leetcode-12. Integer to Roman(整数转换成罗马数字)
- LeetCode | Integer to Roman(整数转换成罗马数字)
- LeetCode | Roman to Integer(罗马数字转换成整数)
- Integer to Roman 整数转换成罗马数字
- Roman to Integer 罗马数字转换成整数
- leetcode 13 Roman to Integer(罗马数字转换为整数)
- [LeetCode]Integer to Roman整数转罗马数字
- (LeetCode) Roman to Integer --- 罗马数字转整数
- Roman to Integer(罗马数字转换成整数)
- [LeetCode]12. Integer to Roman(整数转化为罗马数字)
- leetcode-13. Roman to Integer(罗马数字转化成整数)
- Integer to Roman (罗马数字转换) 【leetcode】
- LeetCode Roman to Integer(罗马数字转换)
- Roman to Integer 罗马数字转化成整数
- Roman to Integer 罗马数字转化成整数
- Integer to Roman (罗马数字转换)
- [C++]LeetCode 12: Integer to Roman(将整数转换为罗马数字)
- Roman to Integer(罗马数字转换为整数)
- java之文本文件与java虚拟机编码以及ASCII码的两种形式转换
- 如果你还是“程序员”,我劝你别创业!
- 配置RabbitMQ远程访问
- Js中的事件委托
- eclipse创建webservice服务
- leetcode-12. Integer to Roman(整数转换成罗马数字)
- Java多线程-并发协作(生产者消费者模型)
- 图半监督学习——标记传播
- 第一次使用git提交本地文件到github
- git:https与ssh的使用区别
- FreeRTOS学习6--软件定时器
- Qt 的 .pro 文件基本格式
- 前端知识图谱
- C语言实现单链表面试题——基础篇(下)