From 24c515282ada19201d460a7e27ddc4979c3eb7ee Mon Sep 17 00:00:00 2001 From: yqq Date: Mon, 27 Sep 2021 16:08:33 +0800 Subject: [PATCH 1/3] =?UTF-8?q?1002.=20=E6=9F=A5=E6=89=BE=E5=B8=B8?= =?UTF-8?q?=E7=94=A8=E5=AD=97=E7=AC=A6,=20=20=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E9=A2=98=E7=9B=AE=E6=8F=8F=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/1002.查找常用字符.md | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/problems/1002.查找常用字符.md b/problems/1002.查找常用字符.md index e02780da..043d20a4 100644 --- a/problems/1002.查找常用字符.md +++ b/problems/1002.查找常用字符.md @@ -12,18 +12,24 @@ [力扣题目链接](https://leetcode-cn.com/problems/find-common-characters/) -给定仅有小写字母组成的字符串数组 A,返回列表中的每个字符串中都显示的全部字符(包括重复字符)组成的列表。例如,如果一个字符在每个字符串中出现 3 次,但不是 4 次,则需要在最终答案中包含该字符 3 次。 +给你一个字符串数组 words ,请你找出所有在 words 的每个字符串中都出现的共用字符( 包括重复字符),并以数组形式返回。你可以按 任意顺序 返回答案。 -你可以按任意顺序返回答案。 +示例 1: -【示例一】 -输入:["bella","label","roller"] +输入:words = ["bella","label","roller"] 输出:["e","l","l"] +示例 2: -【示例二】 -输入:["cool","lock","cook"] +输入:words = ["cool","lock","cook"] 输出:["c","o"] +提示: + +1 <= words.length <= 100 +1 <= words[i].length <= 100 +words[i] 由小写英文字母组成 + + # 思路 From a35adcffbee7ff9c229cff38eff9506b396c0186 Mon Sep 17 00:00:00 2001 From: yqq Date: Mon, 27 Sep 2021 18:51:54 +0800 Subject: [PATCH 2/3] =?UTF-8?q?1035.=E4=B8=8D=E7=9B=B8=E4=BA=A4=E7=9A=84?= =?UTF-8?q?=E7=BA=BF.md,=20=E5=A2=9E=E5=8A=A0Golang=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/1035.不相交的线.md | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/problems/1035.不相交的线.md b/problems/1035.不相交的线.md index a10fd381..8795a77d 100644 --- a/problems/1035.不相交的线.md +++ b/problems/1035.不相交的线.md @@ -109,6 +109,41 @@ class Solution: return dp[-1][-1] ``` + +Golang: + +```go + +func maxUncrossedLines(A []int, B []int) int { + m, n := len(A), len(B) + dp := make([][]int, m+1) + for i := range dp { + dp[i] = make([]int, n+1) + } + + for i := 1; i <= len(A); i++ { + for j := 1; j <= len(B); j++ { + if (A[i - 1] == B[j - 1]) { + dp[i][j] = dp[i - 1][j - 1] + 1; + } else { + dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]); + } + } + } + return dp[m][n]; + +} + +func max(a, b int) int { + if a > b { + return a + } + return b +} +``` + + + JavaScript: ```javascript From a3b5912c1aee1096e7e7cf2c2d9dfd1df0d6a5cc Mon Sep 17 00:00:00 2001 From: yqq Date: Mon, 27 Sep 2021 18:52:44 +0800 Subject: [PATCH 3/3] fix --- problems/1035.不相交的线.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/problems/1035.不相交的线.md b/problems/1035.不相交的线.md index 8795a77d..22cf613b 100644 --- a/problems/1035.不相交的线.md +++ b/problems/1035.不相交的线.md @@ -124,13 +124,13 @@ func maxUncrossedLines(A []int, B []int) int { for i := 1; i <= len(A); i++ { for j := 1; j <= len(B); j++ { if (A[i - 1] == B[j - 1]) { - dp[i][j] = dp[i - 1][j - 1] + 1; + dp[i][j] = dp[i - 1][j - 1] + 1 } else { - dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]); + dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) } } } - return dp[m][n]; + return dp[m][n] }