页面顶部 Top
文件:  root - text - article - 2020 - 01 - convert-roman-numerals-to-decimal.txt
标签: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | 英文 | 主页 | 类别: 计算机科学 | 164 次阅读, 22429 次搜索 | 160 个单词

定阅此目录的博客 | 浏览 | 博客存档
Hi, here's your problem today. This problem was recently asked by Twitter:

Given a Roman numeral, find the corresponding decimal value. Inputs will be between 1 and 3999.

Example:
Input: IX
Output: 9

Input: VII
Output: 7

Input: MCMIV
Output: 1904
Roman numerals are based on the following symbols:

I 1
IV 4
V 5
IX 9
X 10
XL 40
L 50
XC 90
C 100
CD 400
D 500
CM 900
M 1000

Numbers are strings of these symbols in descending order. In some cases, subtractive notation is used to avoid repeated characters. The rules are as follows:
1.) I placed before V or X is one less, so 4 = IV (one less than 5), and 9 is IX (one less than 10)
2.) X placed before L or C indicates ten less, so 40 is XL (10 less than 50) and 90 is XC (10 less than 100).
3.) C placed before D or M indicates 100 less, so 400 is CD (100 less than 500), and 900 is CM (100 less than 1000).


class Solution():
def romanToInt(self, s):
# Fill this in.

n = 'MCMX'
print(Solution().romanToInt(n))
# 1910
标签: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | 英文 | 主页 | 类别: 计算机科学 | 164 次阅读, 22429 次搜索 | 160 个单词 定阅此目录的博客

猜您喜欢...

  1. Daily Interview Problem: Given two arrays, write a function to compute their intersection.
  2. Daily Interview Puzzle: Falling Dominoes
  3. Spectrum Master
  4. Daily Interview Problem: Contiguous Subarray with Maximum Sum
  5. 56 Bytes
  6. Daily Interview Problem: Minimum Removals for Valid Parenthesis
  7. Sorting a list with 3 unique numbers
  8. Algorithm Interview: Subarray With Target Sum
  9. Windows Scripting
  10. Daily Interview Problem: Validate Binary Search Tree

评论 (0)

您的邮件 (不公开域名部分):

您的评论:

悄悄话(发邮件) 颜色 更多笑脸 S x y @

验证码 (点击图片更新):

    当前页暂时没有评论。


最后更新: October 30 2020 14:21:12 | RSS Subscription
牛排怎么做才好吃? | <meta name="机器人" content="不索引, 跟踪" />