class Solution(object):
def intToRoman(self, num):
"""
:type num: int
:rtype: str
"""
values = [ 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 ]
numerals = [ "M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I" ]
list = ''
for i in range(0, len(values)):
while num ...- read more
11. Container With Most Water
read moreclass Solution(object): def maxArea(self, height): """ :type height: List[int] :rtype: int """ end = len(height) - 1 start = 0 max_volume = 0 while end > start: if height[end] >= height[start]: v_height = height[start] start += 1 else: v_height = height[end] end -= 1 if max_volume < (end - start + 1) * v_height: max_volume = (end - start + 1 ...
WOW! Try my Flight Time Calculation!
This tool is used to calculate the flight time between different cities.
I spent one or two days writing this code. This small program is very interesting and useful, especially when you book the airline ticket and do not know how much time it'll cost during each phase.
For ...
read more60.multiplication
read morea=89 b=113 print '%8d'%a print 'x%7d'%b c=b print '-'*8 i=8 while c>0: print '%*d'%(i,(c%10)*a) # * means how many digit, i determines it c=c/10 i-=1 if i==7: # if b is 1 digit decimal, no more ------ print ...
59. A square joining together
read more# A square joining together class Solution(object): def removeoneside(self,nums,side): n=len(nums) res = [[0 for j in range(side + 1)] for i in range(n + 1)] # res[i][j] = max(res[i - 1][j],res[i-1][j-nums[i-1]]+nums[i-1]) for i in range(1, n + 1 ...
58.The least common multiple I
read moreL=[2,8,3,50] s=sorted(L) min=s[-1] max=s[0] for i in range(1,len(s)): max=max*s[i] lcm=min for m in range(max,min,-1): for i in range(len(s)): if m%s[i]==0 and i!=len(s)-1 ...
57.Change the position
read moren=2 if n%2: print (n-1)**2/4 else: print n*(n-2)/4
56.Cut the watermelon
read moren=3 print int((n ** 3 + 5 * n + 6) / 6)
55.In those years we collect cards
read more# -*- coding: utf-8 -*- N=2 b=float(N) a=0.0 i=b while i > 0: a += N/i i -= 1 print "%.2f" % a # 已经有n张卡片,得到下一张与手上不同的卡片的概率是N-n/N,期望是N/(N-n), 1+N/(N-1)+N/(N-2)+.......+N/(1)
54.Back to the longest text string is not simple
read moreL = "caayyhheehhbbbhhjhhyyaac" start, length = 0, 0 for i in range(1,len(L)-1): if L[i] == L[i+1]: s = min(len(L[:i+1]),len(L[i+1:])) a, b = 1, 1 while a < s: if L[i-a] == L[i+1+a]: # to the left 1 pace ...