Skip to content

Commit

Permalink
이슈 #454에서 솔루션 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Feb 23, 2025
1 parent 12391f3 commit 57e334c
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions LeetCode/Roman_to_Integer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Solution {
public:
int romanToInt(string s) {
int result = 0;
unordered_map<char, int> m {
{'I', 1},
{'V', 5},
{'X', 10},
{'L', 50},
{'C', 100},
{'D', 500},
{'M', 1000}
};

for (int i = 0; i < s.length(); i++){
if (m[s[i]] < m[s[i + 1]])
result -= m[s[i]];
else
result += m[s[i]];
}

return result;
}
};

0 comments on commit 57e334c

Please sign in to comment.