Beat this one-liner in Python


  • -1
    W
    return min(reduce(lambda a,b:map(min,zip(map(sum,zip([9**99]+a,b)),map(sum,zip(a+[9**99],b)))),triangle))
    

    What this code does:
    For each level from top, check the sums from previous level to next level (max 2 ways for each next-level element), pick the smaller one. Iterate through the triangle, pick the min from the result.

    Complexity: n^2 time, n^2 space.(due to list copy inside lambda)

    The challenge: show more concise or efficient one liner for this problem.


  • 2
    R

    It's great.
    But... I can't read it T_T


  • 0

    Easy :-P


Log in to reply
 

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