[LeetCode] 13. Roman to Integer
来源:互联网 发布:淘宝卖家怎么打折商品 编辑:程序博客网 时间:2024/06/09 12:31
这题也是直接借鉴来的代码, 感觉这两道罗马字的题不是很有意思, 就直接上码了.
代码来自 https://discuss.leetcode.com/topic/7784/clean-o-n-c-solution/2
int romanToInt(string s) { unordered_map<char, int> T = { { 'I' , 1 }, { 'V' , 5 }, { 'X' , 10 }, { 'L' , 50 }, { 'C' , 100 }, { 'D' , 500 }, { 'M' , 1000 } }; int sum = T[s[s.length() - 1]]; for (int i = s.length() - 2; i >= 0; --i) { if (T[s[i]] < T[s[i + 1]]) sum -= T[s[i]]; else sum += T[s[i]]; } return sum; }
0 0
- LeetCode 13. Roman to Integer
- [LeetCode]13.Roman to Integer
- LeetCode --- 13. Roman to Integer
- [Leetcode] 13. Roman to Integer
- [leetcode] 13.Roman to Integer
- leetcode 13. Roman to Integer
- leetcode 13. Roman to Integer
- LeetCode 13. Roman to Integer
- [LeetCode]13. Roman to Integer
- Leetcode 13. Roman to Integer
- leetcode 13. Roman to Integer
- leetcode 13. Roman to Integer
- LeetCode *** 13. Roman to Integer
- LeetCode 13. Roman to Integer
- LeetCode 13. Roman to Integer
- 【LeetCode】13. Roman to Integer
- Leetcode 13. Roman to Integer
- LeetCode 13. Roman to Integer
- [C++]高效使用关联容器的一些建议
- django haystack update_index 实现自动化 同步
- jQuery学习之jQuery Ajax用法详解
- Linux安装JDK
- 线性表
- [LeetCode] 13. Roman to Integer
- POJ 1200 Crazy Search
- hdu 2222 Keywords Search(AC自动机模板)
- iOS 通知的基本使用传值
- 用jquery实现图片轮播
- 磁盘阵列 RAID 技术原理详解
- 晶/陶振不起振及使用注意事项
- CentOS安装 netdata 实时监视 Linux 系统性能
- [Tarjan缩点 拓扑序DP] SRM 499 1000pts