Integer to Roman Leetcode Python

Source: Internet
Author: User
Given an integer, convert it to a Roman numeral.


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

Build two list match Roman numerals in turn. Some of the more special ones are Roman numerals with two digits.


From http://www.cnblogs.com/zuoyuan/p/3779581.html


This practice is to see the best understand, so it is used.

Class solution:    # @return A string    def inttoroman (self, num):        values=[ 1000,900,500,400,100,90,50,40,10,9,5,4,1]        roman=[' M ', ' CM ', ' D ', ' CD ', ' C ', ' XC ', ' L ', ' XL ', ' X ', ' IX ', ' V ', ' IV ', ' I ' ]        list= ' for        I in range (Len (values)): While            num>=values[i]:                num-=values[i]                List+=roman[i]        return List        


Integer to Roman Leetcode Python

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.