We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 48e0394 commit a0a62bbCopy full SHA for a0a62bb
2 files changed
LeetCode/medium/706.Design HashMap Optimize.cpp
@@ -47,7 +47,7 @@ class MyHashMap {
47
}
48
int get(int key) { return getValueByHash(key); }
49
50
- void remove(int key) { removemap(key); }
+ void remove(int key) { removemap(key);}
51
};
52
53
/**
LeetCode/medium/RomanToIngter.cpp
@@ -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