Can we still get a O(n) solution with O(1) space if the input contains 0?


  • 0

    Can we still get a O(n) solution with O(1) space if the input contains 0?

    Currently, the problem states all the inputs are positive. And solutions are based on the idea to enumerate the 3 cross situations. While, if the input contains 0, i.e.,

    1, 0, 1... there is a cross.


  • 2
    Q

    If 0 is used to signify direction change, one direction change will result in cross (if a positive number follows,) two consecuitive 0s is equivalent to a negative number (if a positive number follows.) The negative number question was already answered.
    Negative Number Question


  • 0

    ur so brilliant~


Log in to reply
 

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