leetcode题解-12. Integer to Roman
来源:互联网 发布:电话号码扫描录入软件 编辑:程序博客网 时间:2024/06/01 15:11
题意:给定一个整型数值,将其转换到罗马数字。输入被保证在1到3999之间。
分析:题目也属于描述不太清楚的题,需要我们自己想到映射规则。百度百科
范围给到3999,感觉情况不多,不断减去需要直接表示的数,而不需要用case代码繁琐的进行判断。
class Solution { public String intToRoman(int num) { String[] strs = {"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"}; int[] nums = {1000,900,500,400,100,90,50,40,10,9,5,4,1}; StringBuilder sb = new StringBuilder(); for(int i = 0; i < nums.length; i++){ while(num >= nums[i]){ num -= nums[i]; sb.append(strs[i]); } } String str = sb.toString(); return str; }}
阅读全文
0 0
- 12. Integer to Roman LeetCode题解
- leetcode题解-12. Integer to Roman
- LeetCode题解:Roman to Integer
- LeetCode题解:Integer to Roman
- LeetCode题解:Roman to Integer
- LeetCode题解:Integer to Roman
- LeetCode 12. Integer to Roman 题解(C++)
- 题解——Leetcode 12. Integer to Roman 难度:Medium
- 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
- LeetCode 12 Integer to Roman题解
- LeetCode题解-12-Integer to Roman
- LeetCode题解-13-Roman to Integer
- 13. Roman to Integer LeetCode题解
- java复习笔记---集合类
- mysql----drop,truncate.delete区别
- Visualizing and Understanding Convolutional Networks笔记1
- 1701 H2 11.13 王建瑜 连续第九天
- 我的Qt学习之路——QPainter基本绘图
- leetcode题解-12. Integer to Roman
- Ubuntu Docker 版本的更新与安装
- SpringMVC+mybatis的配置(依赖maven)
- Ubuntu17.10下输入中文的几个小问题
- c++和java中父类指向子类的比较
- ReactNative高级---JavaScript与Native之间的通信(一)
- 从快速排序开始
- CountDownLatch源码分析
- linux二进制 八进制 十六进制之间的转换