Best Time to Buy and Sell Stock III @ LeetCode (Python)
Palindrome Partitioning II @ LeetCode (Python)

Count and Say @ LeetCode (Python)

kitt posted @ 2014年3月21日 01:07 in LeetCode , 3391 阅读

 

class Solution:
    # @return a string
    def countAndSay(self, n):
        s = '1'
        for i in xrange(n-1):
            prev = newS = ''
            num = 0
            for curr in s:
                if prev != '' and prev != curr:
                    newS += str(num) + prev
                    num = 1
                else:
                    num += 1
                prev = curr
            newS += str(num) + prev
            s = newS
        return s

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter