0013 - roman to integer
Roman numerals are represented by seven different symbols:I V X L C D M
| Symbol | Value |
|---|---|
| I | 1 |
| V | 5 |
| X | 10 |
| L | 50 |
| C | 100 |
| D | 500 |
| M | 1000 |
input: s = III
Output: 3
Expl: III = 3
input: s = LVIII
Output: 58
Expl: L = 50, V = 5, III = 3
input: s = MCMXCIV
Output: 1994
Expl: M = 1000, CM = 900, XC = 90, IV = 4
export default function romanToInt(s: string): number {
console.log("s: ", s);
// ============================================================================
// 1. Handle edge cases
// ----------------------------------------------------------------------------
// if s is empty
// then return 0
// ----------------------------------------------------------------------------
if (s.length === 0) {
console.log("S IS EMPTY");
return 0;
} else {
const mapSymbolValue = new Map([
["I", 1],
["IV", 4],
["V", 5],
["IX", 9],
["X", 10],
["XL", 40],
["L", 50],
["XC", 90],
["C", 100],
["CD", 400],
["D", 500],
["CM", 900],
["M", 1000],
]);
// ============================================================================
// 2. Try examples
// ----------------------------------------------------------------------------
//
// ============================================================================
// 3. Define romanToInt
// ----------------------------------------------------------------------------
return 0;
}
}