7 Lines of Python using recursion, TLE, how to fix it?


  • 0
    T
            def d(h):
                if not h:
                    return 0
                min_val = min(h)
                min_idx = h.index(min_val)
                return max(min_val * len(h), d(h[:min_idx]), d(h[min_idx+1:]))
            return d(heights)
    

Log in to reply
 

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