Jan-08-2021, 09:20 PM
I had the binary compiled into a list so it would be ordered properly.
e.g. integer 32 is 0100000 in the list whereas it's 0000001 otherwise
The output, however, was correct even if it wasn't ordered.
Here's the final, working code:
Appreciate your help! <:
e.g. integer 32 is 0100000 in the list whereas it's 0000001 otherwise
The output, however, was correct even if it wasn't ordered.
Here's the final, working code:
def solution(N): num = N streakstart = False streak = 0 longstreak = 0 while int(num) > 0 : bin = num % 2 num = int(num / 2) if bin == 1 : streakstart = True streak = 0 elif bin == 0 and streakstart is True : streak = streak + 1 else : streak = 0 continue if streak > longstreak : longstreak = streak return longstreak passTurns out I was just thinking too hard about it, thinking it needed proper binary order!
Appreciate your help! <: