LeetCode OJ: 12 Integer to Roman
来源:互联网 发布:房屋装修效果图软件 编辑:程序博客网 时间:2024/05/20 14:19
Total Accepted: 59069 Total Submissions: 155093 Difficulty: Medium
Given an integer, convert it to a roman numeral.
Input is guaranteed to be within the range from 1 to 3999.
Submitted Code
Language:Python
class Solution(object): def intToRoman(self, num): """ :type num: int :rtype: str """ res = '' res += 'M' * (num // 1000) num %= 1000 if num // 100 == 9: res += 'CM' if num // 100 < 9 and num // 100 >= 5: res += 'D' + 'C' * (num // 100 - 5) if num // 100 == 4: res += 'CD' if num // 100 < 4: res += 'C' * (num // 100) num %= 100 if num // 10 == 9: res += 'XC' if num // 10 < 9 and num // 10 >= 5: res += 'L' + 'X' * (num // 10 - 5) if num // 10 == 4: res += 'XL' if num // 10 < 4: res += 'X' * (num // 10) num %= 10 if num == 9: res += 'IX' if num < 9 and num >= 5: res += 'V' + 'I' * (num - 5) if num == 4: res += 'IV' if num < 4: res += 'I' * num return res
0 0
- <LeetCode OJ> 13 / 12 Roman to Integer & Integer to Roman
- LeetCode OJ 12 Integer to Roman
- LeetCode OJ: 12 Integer to Roman
- Leetcode OJ 12 Integer to Roman [Medium]
- LeetCode OJ:Roman to Integer
- LeetCode OJ:Integer to Roman
- LeetCode OJ - Roman to Integer
- LeetCode OJ - Integer to Roman
- [LeetCode OJ]Roman to Integer
- [LeetCode OJ]Integer to Roman
- LeetCode OJ : Roman to Integer
- LeetCode OJ Roman to Integer
- LeetCode OJ Integer to Roman
- LeetCode OJ - Integer to Roman
- LeetCode OJ - Roman to Integer
- LeetCode OJ 13 Roman To Integer
- LeetCode OJ-13-Roman to Integer
- 四、[LeetCode OJ]Integer to Roman
- 夯实基础——类、抽象类和接口的关系
- 集合数组排序之冒泡
- java Date加一天(往后加一天)
- HDU 2099 整除的尾数(格式易题)
- dw1.modify(modstring)
- LeetCode OJ: 12 Integer to Roman
- 【红宝书笔记】DOM2级事件小相关
- PAT1038统计同成绩学生(20)
- EA基础篇绘制ER图
- POJ 2288 Islands and Bridges - 状压dp【TSP】
- android震动器类Vibrator
- ios runtime详解
- 模糊数的C++实现
- 《我怎样毁了我的一生》