Leetcode 11 Container With Most Water

Given a binary tree, determine if it is height-balanced.

For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1.

双指针,容量由低的那一端决定。所指端为低的那一端的指针向中间移动。

def max_area(height)
  maxarea, i, j = 0, 0, height.length - 1
  while i < j
    maxarea = [maxarea,(j-i)*[height[j],height[i]].min].max
    if height[i] < height[j]
      i += 1
    else
      j -= 1
    end
  end
  maxarea
end
posted @ 2015-06-14 17:54  lilixu  阅读(127)  评论(0编辑  收藏  举报