Skip to content

Commit a0a62bb

Browse files
committed
added
1 parent 48e0394 commit a0a62bb

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

LeetCode/medium/706.Design HashMap Optimize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class MyHashMap {
4747
}
4848
int get(int key) { return getValueByHash(key); }
4949

50-
void remove(int key) { removemap(key); }
50+
void remove(int key) { removemap(key);}
5151
};
5252

5353
/**

LeetCode/medium/RomanToIngter.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Solution {
2+
public:
3+
int romanToInt(string s) {
4+
unordered_map<char,int>romanValue;
5+
romanValue['I']=1;
6+
romanValue['V']=5;
7+
romanValue['X']=10;
8+
romanValue['L']=50;
9+
romanValue['C']=100;
10+
romanValue['D']=500;
11+
romanValue['M']=1000;
12+
int last = romanValue[s.back()];
13+
int totalNum = last;
14+
for(int i=s.size()-2; i>=0;i--){
15+
if(romanValue[s[i]] < romanValue[s[i+1]]){
16+
totalNum -= romanValue[s[i]];
17+
}else{
18+
totalNum+= romanValue[s[i]];
19+
}
20+
}
21+
return totalNum;
22+
23+
}
24+
};

0 commit comments

Comments
 (0)