# LeetCode Integer to Roman

LeetCode Integer to Roman

Given an integer, convert it to a roman numeral.

Input is guaranteed to be within the range from 1 to 3999.

```class Solution {
public:
string work(int num, string cur){
if (num >= 1000)
return work(num - 1000, cur + "M");
if (num >= 500){
if (num >= 900)
return work(num - 900, cur + "CM");
return work(num - 500, cur + "D");
}
if (num >= 100){
if (num >= 400)
return work(num - 400, cur + "CD");
return work(num - 100, cur + "C");
}
if (num >= 50){
if (num >= 90)
return work(num - 90, cur + "XC");
return work(num - 50, cur + "L");
}
if (num >= 10){
if (num >= 40)
return work(num - 40, cur + "XL");
return work(num - 10, cur + "X");
}
if (num >= 5){
if (num >= 9)
return work(num - 9, cur + "IX");
return work(num - 5, cur + "V");
}
if (num < 5){
if (num >= 4)
return work(num - 4, cur + "IV");
while (num > 0){
cur += "I";
num--;
}
return cur;
}

}
string intToRoman(int num) {
return work(num, "");
}
};
```

```class Solution {
public:
string intToRoman(int num) {
vector<int> nums = { 1,4,5,9,10,40,50,90,100,400,500,900,1000 };
vector<string> symbol = { "I","IV","V","IX","X","XL","L","XC","C","CD","D","CM","M" };
string ans = "";
for (int i = nums.size() - 1; i >= 0; i--){
while (num >= nums[i]){
ans += symbol[i];
num -= nums[i];
}
}
return ans;
}
};
```