An Easy&Fast Python Way


  • 0
    S

    def main(n):
    if n == 1: return '1'
    str_now = '11'

    for i in range(n-1):
    	str_then = ""
    	count = 1
    	for j in range(len(str_now)-1):
    		if str_now[j]==str_now[j+1]:
    			count += 1
    		else:
    			str_then += str(count) + str_now[j]
    			count	= 1
    	if str_now[-1] != str_now[-2]:
    		str_then += '1'+str_now[-1]
    	else:
    			str_then += str(count) + str_now[-1]
    	str_now = str_then
    return str_now

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.