Skip to content

Instantly share code, notes, and snippets.

@kvalv
Created December 1, 2014 17:52
Show Gist options
  • Select an option

  • Save kvalv/c2db6c2c03bb6637b760 to your computer and use it in GitHub Desktop.

Select an option

Save kvalv/c2db6c2c03bb6637b760 to your computer and use it in GitHub Desktop.
def longestSeq(array):
longestLen = 0
longestLenIndex = 0
currentLen = 0
currentIndex = 0
for i in range(len(array)):
if array[i] == 1 and array[i-1] == 0 or i == 0:
currentIndex = i
if array[i] == 1:
currentLen += 1
if longestLen < currentLen:
longestLen = currentLen
longestLenIndex = currentIndex
if array[i] != 1:
currentLen = 0
return longestLenIndex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment