| https://leetcode.com/problems/roman-to-integer | Easy |
|---|
class Solution {
fun romanToInt(s: String): Int {
var total = 0
var prev = 0
var i = s.length - 1
while (i >= 0) {
val v = when (s[i]) {
'I' -> 1
'V' -> 5
'X' -> 10
'L' -> 50
'C' -> 100
'D' -> 500
else -> 1000
}
total += if (v < prev) -v else v
prev = v
i--
}
return total
}
}