1. 12. Integer to Roman

    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
  2. 11. Container With Most Water

    class 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 ...
    read more
  3. install devstack

    adduser stack sudo visudo Find the part of the file that is labeled "User privilege specification" and change it to the following

    User privilege specification root ALL=(ALL:ALL) ALL stack ALL=(ALL:ALL) ALL Close the file, exit and log in as "stack". Download devstack and create /opt/stack ...

    read more
  4. 60.multiplication

    a=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 ...
    read more
  5. 59. A square joining together

    # 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 ...
    read more
  6. 55.In those years we collect cards

    # -*- 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)
    
    read more

« Page 16 / 23 »

blogroll

social