leetcode 刷题目,总结,记录,备忘 13
来源:互联网 发布:linux 根目录清理 编辑:程序博客网 时间:2024/06/06 04:43
leetcode13Roman to Integer
Given a roman numeral, convert it to an integer.
Input is guaranteed to be within the range from 1 to 3999.
这个题目,,不说了,,,去百度罗马数字的一些规则,,,比如C在D或者M前面是-100的意思。上代码。。。
class Solution {public: int romanToInt(string s) { int sum = 0; char pre = ' '; for (string::iterator it = s.begin(); it != s.end(); ++it) { switch (*it) { case 'M': sum += 1000; break; case 'D': sum += 500; break; case 'C': if (*(it +1) == 'M' || *(it+1) == 'D') sum -= 100; else sum += 100; break; case 'L': sum += 50; break; case 'X': if (*(it +1) == 'L' || *(it+1) == 'C') sum -= 10; else sum += 10; break; case 'V':sum += 5; break; case 'I': if (*(it +1) == 'V' || *(it +1) == 'X') sum -= 1; else sum += 1; break; } } return sum; }};
0 0
- leetcode 刷题目,总结,记录,备忘 13
- leetcode刷题目 ,总结,记录,备忘206
- leetcode刷题目 总结 记录 备忘11
- leetcode 总结,记录,备忘。153
- leetcode刷题。总结,记录,备忘 104
- leetcode刷题。总结,记录,备忘 100
- leetcode刷题。总结,记录,备忘 191
- leetcode刷题。总结,记录,备忘。168
- leetcode刷题, 总结,记录,备忘 171
- leetcode刷题 ,总结,记录,备忘。144
- leetcode刷题,总结,记录, 备忘 141
- leetcode刷题,总结,记录,备忘。116
- leetcode刷题,总结,记录,备忘。96
- leetcode刷题。记录,总结,备忘。217
- leetcode 刷题, 总结,记录,备忘 35
- leetcode刷题,总结,记录,备忘 226
- leetcode刷题,总结,记录,备忘 169
- leetcode刷题,总结,记录,备忘137
- Java文件 File练习-递归显示某一目录下的所有文件
- MySQL学习系列9:视图
- 第五单元5.19
- LeetCode_Stack_Maximal Rectangle
- [leetcode] 95.Unique Binary Search Trees II
- leetcode 刷题目,总结,记录,备忘 13
- 2299 Poj Ultra-QuickSort(归并排序求逆序数)
- [Java]学习笔记,随笔【四】
- Web 开发的 JavaScript 框架资料收集(15款)
- Java文件 File练习-递归删除带内容的目录
- 用make编译多个.c文件
- JavaScript语法 (顺序+判断+选择+循环+其他=五种语句)演示
- ucore操作系统实验lab4 -- 内核线程管理
- 题目1152:点菜问题