Brick Wall


  • 1

    Click here to see the full article post


  • 0
    Y

    It's an awesome solution. But may I ask why we traverse from left to right to build "sum" instead of traversing right to left?


  • 0

    @yujun you can do that as well.


  • 0

    We can use a variable to record the maximum count each time when putting keys to the map. Hence we do not need to traverse the map's keySet().


  • 0
    A

    If wall width >> wall height, the approach #3 is not optimal. We do not need a HashMap with all gap positions. We just need a Heap with the closest gap locations. Then, the space complexity is O(height).


Log in to reply
 

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