classSolution:defintToRoman(self,num:int)->str:ifnum==0:return''symbols=[('I','V'),('X','L'),('C','D'),('M')]roman=''numOfDigit=0whilenum>0:c=''digit=num%10ifdigit==4:c=symbols[numOfDigit][0]+symbols[numOfDigit][1]elifdigit==9:c=symbols[numOfDigit][0]+symbols[numOfDigit+1][0]else:ifdigit>4:c=symbols[numOfDigit][1]foriinrange(digit%5):c+=symbols[numOfDigit][0]# next digit
num//=10numOfDigit+=1roman=c+romanreturnroman
Top comments (0)
Subscribe
We're a place where coders share, stay up-to-date and grow their careers.
Top comments (0)