최대 1 분 소요

Link

class Solution:
    def maxArea(self, height: List[int]) -> int:
        i, j = 0, len(height)-1
        mx = 0
        while i < j:
          # point 1. For calculating 'area', we have to find 'height' of 'area'.
          # k is the 'height' of it
            k = min(height[i], height[j])
            amount = (j-i)*k
          # point 2. For finding and renewing the max amount as this problem's condition,    
          # we have to method of 'max'.
            mx = max(mx, amount)
            if height[i] < height[j]:
                i += 1
            else:
                j -= 1
        return mx
        

Summary

  1. For calculating ‘area’, we have to find ‘height’ of ‘area’. ‘k’ is the ‘height’ of it
  2. For finding and renewing the max amount as this problem’s condition, we have to method of ‘max’ .

댓글남기기