Skip to content

Instantly share code, notes, and snippets.

@Chemasmas
Created February 19, 2021 06:18
Show Gist options
  • Save Chemasmas/cec94131fca3bfe1f6f72f850cad2f72 to your computer and use it in GitHub Desktop.
Save Chemasmas/cec94131fca3bfe1f6f72f850cad2f72 to your computer and use it in GitHub Desktop.
Solucion de Chemasmas
object Solution {
def intToRoman(num: Int): String = {
return if(num >= 1000)
"M" + intToRoman(num-1000)
else if(num >= 900)
"CM" + intToRoman(num-900)
else if(num >= 500)
"D" + intToRoman(num-500)
else if(num >= 400)
"CD" + intToRoman(num-400)
else if(num >= 100)
"C" + intToRoman(num-100)
else if(num >= 90)
"XC" + intToRoman(num-90)
else if(num >= 50)
"L" + intToRoman(num-50)
else if(num >= 40)
"XL" + intToRoman(num-40)
else if(num >= 10)
"X" + intToRoman(num-10)
else if(num >= 9)
"IX" + intToRoman(num-9)
else if(num >= 5)
"V" + intToRoman(num-5)
else if(num >= 4)
"IV" + intToRoman(num-4)
else if(num > 0)
"I" + intToRoman(num-1)
else
""
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment