i wrote this code for integer to roman conversion , idk whats wrong in here....help pls.
class Solution {
public String intToRoman(int num) {
String ans = "";
HashMap<String,Integer> map = new HashMap<>();
map.put("M",1000);
map.put("CM",900);
map.put("D",500);
map.put("CD",400);
map.put("C",100);
map.put("XC",90);
map.put("L",50);
map.put("XL",40);
map.put("X",10);
map.put("IX",9);
map.put("V",5);
map.put("IV",4);
map.put("I",1);
for(String rm: map.keySet()){
while(num>=map.get(rm)){
ans = ans + rm;
num = num-map.get(rm);
}
}
return ans;
}
}