A solution better than O(n): Best Case O(logn), Worse Case O(n),

  • 0

    The main idea is to use binary search to find the rightmost value that equal to current value.

    And, for the upper bound of search range, we don't need to set it as the end of the array, instead, we can double the length of range each time, until it's unequal to current value.

Log in to reply

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