문제 출처: https://leetcode.com/problems/roman-to-integer/
class Solution {
func romanToInt(_ s: String) -> Int {
let dict = ["I":1, "V":5, "X":10, "L":50, "C":100, "D":500, "M":5000]
var intArray = [Int]()
var result = 0
for i in s {
for j in dict.keys {
if String(i) == j {
intArray.append(dict[String(i)]!)
}
}
}
for i in 0..<intArray.count {
if i+1 == intArray.count {
break
} else {
if intArray[i] < intArray[i+1] {
intArray[i] = intArray[i] * -1
}
}
}
for i in 0..<intArray.count {
result = result + intArray[i]
}
return result
}
}