fork download
  1.  
  2. A = [3,2,5,4,4,4,4,2,4,4]
  3.  
  4. def findLongestContinuousSection(A):
  5. if len(A) == 0:
  6. return
  7. longestStart = 0
  8. longestStop = 0
  9. longestLength = 0
  10. longestVal = 0
  11. curStart = 0
  12. curStop = 0
  13. curLength = 1
  14. curVal = A[0]
  15. for k in range(1,len(A)-1):
  16. if curVal != A[k] and curLength > longestLength: # record cur as longest
  17. longestVal = curVal
  18. longestStart = curStart
  19. longestStop = curStop
  20. longestLength = curLength
  21. curStart = k
  22. curStop = k
  23. curLength = 1
  24. curVal = A[k]
  25. else: # continue to build current streak
  26. curStop = k
  27. curLength += 1
  28. return (longestStart, longestStop, longestLength, longestVal)
  29.  
  30. print findLongestContinuousSection(A)
  31.  
  32.  
Success #stdin #stdout 0s 23296KB
stdin
Standard input is empty
stdout
(3, 6, 4, 4)