Integer to Roman Conversion
Solution to integer to roman conversion leetcode problem.
class Solution {
public String intToRoman(int num) {
StringBuilder resultStore = new StringBuilder();
String[] st = new String[] {"I", "IV", "V", "IX", "X", "XL", "L", "XC", "C", "CD", "D", "CM", "M"};
int[] nt = new int[] { 1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000};
int mutableNum = num;
for (int i=nt.length-1; i>=0; i--) {
if (mutableNum == 0)
break;
if (nt[i] == mutableNum) {
resultStore.append(st[i]);
break;
}
else if (nt[i] < mutableNum) {
int otherFactor = mutableNum / nt[i];
for(int j=0;j<otherFactor;j++)
resultStore.append(st[i]);
mutableNum = mutableNum % nt[i];
}
}
return resultStore.toString();
}
}