반응형
leetcode.com/problems/roman-to-integer/
Solution
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
int romanToInt(char * s){
int value = 0;
int cur;
int old = 4000;
while(*s){
if(*s=='I') cur = 1;
else if(*s=='V') cur = 5;
else if(*s=='X') cur = 10;
else if(*s=='L') cur = 50;
else if(*s=='C') cur = 100;
else if(*s=='D') cur = 500;
else if(*s=='M') cur = 1000;
if(old < cur){
value -= old;
cur -= old;
}
old = cur;
value += cur;
s++;
}
return value;
}
|
cs |
반응형
'코딩테스트 > Leetcode' 카테고리의 다른 글
Leetcode - [Medium]6. ZigZag Conversion (0) | 2021.03.25 |
---|---|
Leetcode - [Easy]14. Longest Common Prefix (0) | 2021.03.22 |
Leetcode - [Medium]3. Longest Substring Without Repeating Characters (0) | 2021.03.07 |
Leetcode - [Medium]2. Add Two Numbers (0) | 2021.03.04 |
Leetcode - [Easy]9. Palindrome Number (0) | 2021.03.04 |