[LeetCode][Python3] 13. Roman to Integer
2018. 9. 11. 00:29 |
프로그래밍/LeetCode
Problem :
https://leetcode.com/problems/roman-to-integer/description/
My Solution :
class Solution:
def romanToInt(self, s):
"""
:type s: str
:rtype: int
"""
result = 0
roman_int = dict(I=1, V=5, X=10, L=50, C=100, D=500, M=1000)
for i in range(1, len(s)):
if roman_int[s[i-1]] < roman_int[s[i]]:
result -= roman_int[s[i-1]]
else:
result += roman_int[s[i-1]]
result += roman_int[s[-1]]
return result
Comment :
좋은 아이디어가 떠오르지 않아 Discuss를 참조하였다 ㅠㅠ
'프로그래밍 > LeetCode' 카테고리의 다른 글
[LeetCode][Python3] 27. Remove Element (0) | 2018.09.11 |
---|---|
[LeetCode][Python3] 26. Remove Duplicates from Sorted Array (0) | 2018.09.11 |
[LeetCode][Python3] 7. Reverse Integer (0) | 2018.09.11 |
[LeetCode][Python3] 21. Merge Two Sorted Lists (0) | 2018.09.11 |
[LeetCode][Python3] 20. Valid Parentheses (0) | 2018.09.11 |
[LeetCode][Python3] 14. Longest Common Prefix (0) | 2018.09.11 |
[LeetCode][Python3] 9. Palindrome Number (0) | 2018.09.10 |
[LeetCode][Python3] 1. Two Sum (0) | 2018.09.10 |
최근에 달린 댓글 최근에 달린 댓글