LeetCode 13. Roman to Integer
2022.07.18
問題
typescript
typescriptfunction romanToInt(s: string): number { const romanIntMap = { I: 1, V: 5, X: 10, L: 50, C: 100, D: 500, M: 1000, } let n = 0 for(let i = 0; i < s.length; i++) { if(i+1 < s.length && romanIntMap[s[i]] < romanIntMap[s[i+1]]){ n -= romanIntMap[s[i]] } else{ n += romanIntMap[s[i]] } } return n };
- carryで繰り上がりをうまく渡していく
current3 = dummy
はよく使う