Skip to content

Instantly share code, notes, and snippets.

View treminaor's full-sized avatar
🎯
Focusing

Andrew King treminaor

🎯
Focusing
View GitHub Profile
@treminaor
treminaor / romanToInt.cpp
Created March 22, 2019 19:40
Roman to Integer C++ LeetCode
class Solution {
public:
int romanToInt(string s) {
int i = 0; int result = 0;
enum r {I = 1, V = 5, X = 10, L = 50, C = 100, D = 500, M = 1000};
while(i < s.length())
{
switch(s[i])
{
case 'M': result += M; break;
@treminaor
treminaor / intToRoman.cpp
Created March 22, 2019 19:39
Integer to Roman C++ LeetCode
class Solution {
public:
string intToRoman(int num) {
string result = "";
int numerals[7] = { 1, 5, 10, 50, 100, 500, 1000 };
char numerals_key[7] = { 'I', 'V', 'X', 'L', 'C', 'D', 'M'};
int remainders[6] = { 4, 9, 40, 90, 400, 900 };
char* remainders_key[6] = { "IV", "IX", "XL", "XC", "CD", "CM"};