diff --git a/problems/1002.查找常用字符.md b/problems/1002.查找常用字符.md index 7a9677ad..56feb20c 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] 由小写英文字母组成 + + # 思路 diff --git a/problems/1035.不相交的线.md b/problems/1035.不相交的线.md index 04f8de09..e9b03e24 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