LeetCode 13 Roman to Integer
来源:互联网 发布:传奇db数据库编辑器 编辑:程序博客网 时间:2024/06/06 12:34
题意:
把罗马数字变成数字。
思路:
简单模拟。我用了个map有点蠢,其实写个switch更好点吧。
代码:
//// Created by house on 1/9/17.//class Solution {public: int romanToInt(string s) { map<char, int> toint; toint['I'] = 1; toint['V'] = 5; toint['X'] = 10; toint['L'] = 50; toint['C'] = 100; toint['D'] = 500; toint['M'] = 1000; int ans = 0; for (int i = 0; i < s.size(); ++i) { int cur = toint[s[i]]; int nex = -1; if (i + 1 < s.size() && toint[s[i + 1]] > cur) { cur = -cur; } ans += cur; } return ans; }};
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-13Roman to Integer
- leetcode 13: Roman to Integer
- Leetcode 13 Roman to Integer
- C# winform 限制程序多开
- 面试题
- CSS3动画—— transition
- Serializable&邮件收发端口
- Swift 3.0 遇到的一些问题
- LeetCode 13 Roman to Integer
- Qt v5.6.2 bug
- 微信小程序,安全性有多高?黑客能盗走你的红包吗
- 根据key从Properties文件中加载指定的value
- java中Token验证
- C++ PRIMER PLUS 第六版编程答案(五)
- json理解
- 14、二叉树
- C++、java和matlab最近使用的一些比较