From fdac2e40b4d5fecd9b195597f89b311d5c0e4693 Mon Sep 17 00:00:00 2001 From: Azureki Date: Sun, 9 Sep 2018 21:50:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lc892-2.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lc892-2.py b/lc892-2.py index e8c70d9..6e86f17 100644 --- a/lc892-2.py +++ b/lc892-2.py @@ -4,6 +4,9 @@ def surfaceArea(self, grid): :type grid: List[List[int]] :rtype: int """ + + # 外面,包括凹下去的。 + # 欣宜还是考虑复杂了,负的也没关系,用绝对值就行了。不需要两个方向都跑一次。 def helper(heights): cur = 0 ret = 0 @@ -14,11 +17,14 @@ def helper(heights): return ret area = 0 + # 每一行 for row in grid: area += helper(row) + # 每一列 for col in zip(*grid): area += helper(col) + # 上下底面 area += sum(2 for row in grid for h in row if h > 0) return area