GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — leetcode/python/012_Integer_to_Roman.py at master · naironics/leetcode

Expand file tree

/

012_Integer_to_Roman.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
47 lines (45 loc) · 1.46 KB
/

012_Integer_to_Roman.py

Copy path

File metadata and controls

47 lines (45 loc) · 1.46 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# class Solution(object):
# def intToRoman(self, num):
# """
# :type num: int
# :rtype: str
# """
#
class Solution(object):
# def intToRoman(self, num):
# #http://www.rapidtables.com/convert/number/how-number-to-roman-numerals.htm
# roman_dim = [[1000, 'M'], [900, 'CM'], [500, 'D'], [400, 'CD'],
# [100, 'C'], [90, 'XC'], [50, 'L'], [40, 'XL'], [10, 'X'],
# [9,'IX'], [5, 'V'], [4, 'IV'], [1, 'I']]
# if num == 0:
# return ''
# roman_str = ''
# current, dim = num, 0
# while current != 0:
# while current // roman_dim[dim][0] == 0:
# dim += 1
# while current - roman_dim[dim][0] >= 0:
# current -= roman_dim[dim][0]
# roman_str += roman_dim[dim][1]
# return roman_str
def intToRoman(self, num):
values = [1000, 900, 500, 400,
100, 90, 50, 40,
10, 9, 5, 4, 1]
symbols = ["M", "CM", "D", "CD",
"C", "XC", "L", "XL",
"X", "IX", "V", "IV",
"I"]
roman = ''
i = 0
while num > 0:
k = num / values[i]
for j in range(k):
roman += symbols[i]
num -= values[i]
i += 1
return roman
if __name__ == '__main__':
# begin
s = Solution()
print s.intToRoman(90)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.