第 20 天的 Leetcode 要開始拉,那我們就開始吧 ─=≡Σ(((っ›´ω`‹ )っ!
今天要寫的題目是 Roman to Integer,顧名思義就是把羅馬數字轉換成一般常見的阿拉伯數字。
Example:
Input: s = "III"
Output: 3
Input: s = "IV"
Output: 4
Input: s = "MCMXCIV"
Output: 1994
Explanation: M = 1000, CM = 900, XC = 90 and IV = 4.
困難的點是必須要去判斷像 IV
這種由兩個字組成的值。
I can be placed before V (5) and X (10) to make 4 and 9.
X can be placed before L (50) and C (100) to make 40 and 90.
C can be placed before D (500) and M (1000) to make 400 and 900.
怕超過時間,先待補