Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. class Solution:
  2. def romanToInt(self, s: str) -> int:
  3. value = []
  4. normal = {
  5. "I": 1,
  6. "V": 5,
  7. "X": 10,
  8. "L": 50,
  9. "C": 100,
  10. "D": 500,
  11. "M": 1000
  12. }
  13. notnormal = {
  14. "IV": 4,
  15. "IX": 9,
  16. "XL": 40,
  17. "XC": 90,
  18. "CD": 400,
  19. "CM": 900
  20. }
  21.  
  22.  
  23. result=0
  24. i=0
  25. notnormalb = ''
  26. while i < len(s):
  27. if (i + 1) < len(s):
  28. notnormalb = s[i] + s[i + 1]
  29. if notnormal.get(notnormalb):
  30. result += notnormal.get(notnormalb)
  31. i += 1
  32. else:
  33. if normal.get(s[i]):
  34. result += normal.get(s[i])
  35. else:
  36. if normal.get(s[i]):
  37. result += normal.get(s[i])
  38. i += 1
  39. return result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement