2014年2月18日 星期二

最長平台(plateau)

至一個陣列中,取出最長的平台出來,作者使用length 記錄當前的長度,並測量後面的長度
只比較list[i], list[length-i],當兩者相同時,把length+1
 
list=[7,7,8,1,2,3,3,4,4,5,5,5,6,7,7,7]

length=len(list)
#sort a list to become increasing array
sorted_list=sorted(list)
print sorted_list
length=1
for i in range(len(sorted_list)):
    if(sorted_list[i]==sorted_list[i-length]):
        length=length+1


print "the longest plateau is %d" % length

沒有留言:

How to restore a deleted onenote page

復原不小心誤刪的onenote