From 4926d659a7937c880e631c4cde4f017d7e3e193e Mon Sep 17 00:00:00 2001 From: YusenAi <59075298+Aitensa@users.noreply.github.com> Date: Wed, 1 Sep 2021 16:39:46 +0800 Subject: [PATCH 1/3] =?UTF-8?q?Update=200714.=E4=B9=B0=E5=8D=96=E8=82=A1?= =?UTF-8?q?=E7=A5=A8=E7=9A=84=E6=9C=80=E4=BD=B3=E6=97=B6=E6=9C=BA=E5=90=AB?= =?UTF-8?q?=E6=89=8B=E7=BB=AD=E8=B4=B9=EF=BC=88=E5=8A=A8=E6=80=81=E8=A7=84?= =?UTF-8?q?=E5=88=92=EF=BC=89.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...€ä½³æ—¶æœºå«æ‰‹ç»­è´¹ï¼ˆåЍæ€è§„划).md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/problems/0714.ä¹°å–è‚¡ç¥¨çš„æœ€ä½³æ—¶æœºå«æ‰‹ç»­è´¹ï¼ˆåЍæ€è§„划).md b/problems/0714.ä¹°å–è‚¡ç¥¨çš„æœ€ä½³æ—¶æœºå«æ‰‹ç»­è´¹ï¼ˆåЍæ€è§„划).md index 50db8868..b854c65c 100644 --- a/problems/0714.ä¹°å–è‚¡ç¥¨çš„æœ€ä½³æ—¶æœºå«æ‰‹ç»­è´¹ï¼ˆåЍæ€è§„划).md +++ b/problems/0714.ä¹°å–è‚¡ç¥¨çš„æœ€ä½³æ—¶æœºå«æ‰‹ç»­è´¹ï¼ˆåЍæ€è§„划).md @@ -152,6 +152,24 @@ class Solution: ``` Go: +```Go +func maxProfit(prices []int, fee int) int { + n := len(prices) + dp := make([][2]int, n) + dp[0][0] = -prices[0] + for i := 1; i < n; i++ { + dp[i][1] = max(dp[i-1][1], dp[i-1][0]+prices[i]-fee) + dp[i][0] = max(dp[i-1][0], dp[i-1][1]-prices[i]) + } + return dp[n-1][1] +} +func max(a, b int) int { + if a > b { + return a + } + return b +} +``` Javascript: ```javascript From e6fdf1023336647471c122b68779e34a2ee2facd Mon Sep 17 00:00:00 2001 From: YusenAi <59075298+Aitensa@users.noreply.github.com> Date: Wed, 1 Sep 2021 16:45:15 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=200714.=E4=B9=B0?= =?UTF-8?q?=E5=8D=96=E8=82=A1=E7=A5=A8=E7=9A=84=E6=9C=80=E4=BD=B3=E6=97=B6?= =?UTF-8?q?=E6=9C=BA=E5=90=AB=E6=89=8B=E7=BB=AD=E8=B4=B9=EF=BC=88=E5=8A=A8?= =?UTF-8?q?=E6=80=81=E8=A7=84=E5=88=92=EF=BC=89.md=20Go=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ....ä¹°å–è‚¡ç¥¨çš„æœ€ä½³æ—¶æœºå«æ‰‹ç»­è´¹ï¼ˆåЍæ€è§„划).md | 1 + 1 file changed, 1 insertion(+) diff --git a/problems/0714.ä¹°å–è‚¡ç¥¨çš„æœ€ä½³æ—¶æœºå«æ‰‹ç»­è´¹ï¼ˆåЍæ€è§„划).md b/problems/0714.ä¹°å–è‚¡ç¥¨çš„æœ€ä½³æ—¶æœºå«æ‰‹ç»­è´¹ï¼ˆåЍæ€è§„划).md index b854c65c..7c54a2fe 100644 --- a/problems/0714.ä¹°å–è‚¡ç¥¨çš„æœ€ä½³æ—¶æœºå«æ‰‹ç»­è´¹ï¼ˆåЍæ€è§„划).md +++ b/problems/0714.ä¹°å–è‚¡ç¥¨çš„æœ€ä½³æ—¶æœºå«æ‰‹ç»­è´¹ï¼ˆåЍæ€è§„划).md @@ -163,6 +163,7 @@ func maxProfit(prices []int, fee int) int { } return dp[n-1][1] } + func max(a, b int) int { if a > b { return a From 34e8e4d5149159c9f95b63246e59219a930b78ea Mon Sep 17 00:00:00 2001 From: YusenAi <59075298+Aitensa@users.noreply.github.com> Date: Thu, 2 Sep 2021 13:12:36 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=200968.=E7=9B=91?= =?UTF-8?q?=E6=8E=A7=E4=BA=8C=E5=8F=89=E6=A0=91.md=20=20Go=E7=89=88?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0968.ç›‘æŽ§äºŒå‰æ ‘.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/problems/0968.ç›‘æŽ§äºŒå‰æ ‘.md b/problems/0968.ç›‘æŽ§äºŒå‰æ ‘.md index 737e92a0..a5fa71a7 100644 --- a/problems/0968.ç›‘æŽ§äºŒå‰æ ‘.md +++ b/problems/0968.ç›‘æŽ§äºŒå‰æ ‘.md @@ -368,7 +368,34 @@ class Solution: return result ``` Go: +```go +const inf = math.MaxInt64 / 2 +func minCameraCover(root *TreeNode) int { + var dfs func(*TreeNode) (a, b, c int) + dfs = func(node *TreeNode) (a, b, c int) { + if node == nil { + return inf, 0, 0 + } + lefta, leftb, leftc := dfs(node.Left) + righta, rightb, rightc := dfs(node.Right) + a = leftc + rightc + 1 + b = min(a, min(lefta+rightb, righta+leftb)) + c = min(a, leftb+rightb) + return + } + _, ans, _ := dfs(root) + return ans +} + +func min(a, b int) int { + if a <= b { + return a + } + return b +} + +``` Javascript: ```Javascript var minCameraCover = function(root) {