Leetcode, Roman To Integer, Scala, Programming, Algorithms.
roman(s(0)) for (i <- 1 until s.length) { val currentValue = roman(s(i)) sum += (if (currentValue > prevValue) -prevValue else prevValue) prevValue = currentValue } sum += prevValue sum } } Time and Space Complexity Time Complexity: O(n), with n being the length of the string. The map lookups are