class Solution: # @return a string def itergen(self,a): k,last,result = 1,a[0],'' for i in range(1,len(a)): if last==a[i]:k+=1 else: result = result+str(k)+last k=1 last = a[i] result = result+str(k)+last return result def countAndSay(self, n): if n==0: return '' rst='1' for i in range(n-1): rst=self.itergen(rst) return rst
Friday, September 12, 2014
Leetcode: Count and Say @Python
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment