-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathInteger-To-Roman.py
43 lines (40 loc) · 1.03 KB
/
Integer-To-Roman.py
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
#! /usr/bin/env python
#! -*- coding=utf-8 -*-
# Date: 2019-11-03
# Author: Bryce
#Python Solution 1:
class Solution(object):
def intToRoman(self, num):
"""
:type num: int
:rtype: str
"""
res = ''
val= [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"]
for i in range(0,len(roman)):
while num >= val[i] :
num -= val[i]
res += roman[i]
return res
#Python Solution 2:
class Solution(object):
def maxArea(self, height):
"""
:type height: List[int]
:rtype: int
"""
res = 0
if len(height) < 2:
return 0
i = 0
j = len(height) -1
while i < j:
width = j - i
high = min (height[i],height[j])
res = max(res, width * high)
if height[i] > height[j]:
j -=1
else:
i +=1
return res