LeetCode编程练习 - Roman to Integer学习心得
2017-09-25 17:16
531 查看
题目:
Given a roman numeral, convert it to an integer.
Input is guaranteed to be within the range from 1 to 3999.
给定一个罗马数字,将其转换为整数,输入保证在从1到3999之间。
思路:
查看罗马数字表,I对应1,V对应5,X对应10,L对应50,C对应100,D对应500,M对应1000,罗马数计算规则为,相同的数字连写,表示的数等于这些数相加,但连续的数重复不能超过三次,比如说III
= 3;当小的数在打的右边,所表示的数等于这些数字相加,VII = 7;当小的数在大的数左边(除I、X、C),所表示的数等于大的数减去小的数,IV = 4。
Given a roman numeral, convert it to an integer.
Input is guaranteed to be within the range from 1 to 3999.
给定一个罗马数字,将其转换为整数,输入保证在从1到3999之间。
思路:
查看罗马数字表,I对应1,V对应5,X对应10,L对应50,C对应100,D对应500,M对应1000,罗马数计算规则为,相同的数字连写,表示的数等于这些数相加,但连续的数重复不能超过三次,比如说III
= 3;当小的数在打的右边,所表示的数等于这些数字相加,VII = 7;当小的数在大的数左边(除I、X、C),所表示的数等于大的数减去小的数,IV = 4。
相关文章推荐
- LeetCode编程练习 - Best Time to Buy and Sell Stock II学习心得
- LeetCode编程练习 - Reverse Integer学习心得
- LeetCode编程练习 - Best Time to Buy and Sell Stock学习心得
- LeetCode编程练习 - Remove Element学习心得
- LeetCode Online Judge 题目C# 练习 - Roman to Integer
- LeetCode编程练习 - Merge Two Sorted Lists学习心得
- LeetCode编程练习 - Happy Number学习心得
- Leetcode练习-Roman to Integer"M": 1000, "D": 500, "C": 100, "L": 50, "X": 10, "V": 5, "I": 1
- LeetCode编程练习 - Count Primes学习心得
- LeetCode编程练习 - Factorial Trailing Zeroes学习心得
- LeetCode编程练习 - Move Zeroes学习心得
- LeetCode编程练习 - Merge Sorted Array学习心得
- LeetCode编程练习 - Power of Two学习心得
- LeetCode编程练习 - Reverse Vowels of a String学习心得
- LeetCode编程练习 - Add Digits学习心得
- LeetCode编程练习 - Intersection of Two Arrays II学习心得
- LeetCode编程练习 - Remove Duplicates from Sorted Array学习心得
- LeetCode 编程练习 - Two Sum II - Input array is sorted学习心得
- LeetCode编程练习 - Remove Duplicates from Sorted List学习心得
- Leetcode在线编程 integer-to-roman