From 1fcb8402232e4db9fb1af3312232f7c2e3f26ee5 Mon Sep 17 00:00:00 2001 From: tw2665 <55668073+tw2665@users.noreply.github.com> Date: Tue, 18 May 2021 15:45:10 -0400 Subject: [PATCH 1/4] =?UTF-8?q?Update=200454.=E5=9B=9B=E6=95=B0=E7=9B=B8?= =?UTF-8?q?=E5=8A=A0II.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0454.四数相加II.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/problems/0454.四数相加II.md b/problems/0454.四数相加II.md index a2ef928b..ad928a3f 100644 --- a/problems/0454.四数相加II.md +++ b/problems/0454.四数相加II.md @@ -121,6 +121,37 @@ class Solution { Python: +``` +class Solution(object): + def fourSumCount(self, nums1, nums2, nums3, nums4): + """ + :type nums1: List[int] + :type nums2: List[int] + :type nums3: List[int] + :type nums4: List[int] + :rtype: int + """ + # use a dict to store the elements in nums1 and nums2 and their sum + hashmap = dict() + for n1 in nums1: + for n2 in nums2: + if n1 + n2 in hashmap: + hashmap[n1+n2] += 1 + else: + hashmap[n1+n2] = 1 + + # if the -(a+b) exists in nums3 and nums4, we shall add the count + count = 0 + for n3 in nums3: + for n4 in nums4: + key = - n3 - n4 + if key in hashmap: + count += hashmap[key] + return count + + +``` + Go: From 830381313abb85357f180f6315e0e1c28c63c01d Mon Sep 17 00:00:00 2001 From: tw2665 <55668073+tw2665@users.noreply.github.com> Date: Tue, 18 May 2021 15:53:09 -0400 Subject: [PATCH 2/4] =?UTF-8?q?Update=200383.=E8=B5=8E=E9=87=91=E4=BF=A1.m?= =?UTF-8?q?d?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0383.赎金信.md | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/problems/0383.赎金信.md b/problems/0383.赎金信.md index 2f7ae4d8..527945fa 100644 --- a/problems/0383.赎金信.md +++ b/problems/0383.赎金信.md @@ -136,7 +136,34 @@ class Solution { ``` Python: - +``` +class Solution(object): + def canConstruct(self, ransomNote, magazine): + """ + :type ransomNote: str + :type magazine: str + :rtype: bool + """ + + # use a dict to store the number of letter occurance in ransomNote + hashmap = dict() + for s in ransomNote: + if s in hashmap: + hashmap[s] += 1 + else: + hashmap[s] = 1 + + # check if the letter we need can be found in magazine + for l in magazine: + if l in hashmap: + hashmap[l] -= 1 + + for key in hashmap: + if hashmap[key] > 0: + return False + + return True +``` Go: From c628620ceddbdbe236b1cbb6cc597431642ae260 Mon Sep 17 00:00:00 2001 From: QuinnDK <39618652+QuinnDK@users.noreply.github.com> Date: Wed, 19 May 2021 10:07:40 +0800 Subject: [PATCH 3/4] =?UTF-8?q?Update=200516.=E6=9C=80=E9=95=BF=E5=9B=9E?= =?UTF-8?q?=E6=96=87=E5=AD=90=E5=BA=8F=E5=88=97.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0516.最长回文子序列.md | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/problems/0516.最长回文子序列.md b/problems/0516.最长回文子序列.md index d7acef99..7736b69f 100644 --- a/problems/0516.最长回文子序列.md +++ b/problems/0516.最长回文子序列.md @@ -173,6 +173,33 @@ Python: Go: +```Go +func longestPalindromeSubseq(s string) int { + lenth:=len(s) + dp:=make([][]int,lenth) + for i:=0;i=0;i--{ + for j:=i+1;j Date: Wed, 19 May 2021 10:25:58 +0800 Subject: [PATCH 4/4] =?UTF-8?q?Update=200055.=E8=B7=B3=E8=B7=83=E6=B8=B8?= =?UTF-8?q?=E6=88=8F.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0055.跳跃游戏.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/problems/0055.跳跃游戏.md b/problems/0055.跳跃游戏.md index a25c831a..ae2cbd1e 100644 --- a/problems/0055.跳跃游戏.md +++ b/problems/0055.跳跃游戏.md @@ -122,6 +122,24 @@ class Solution: ``` Go: +```Go +func canJUmp(nums []int) bool { + if len(nums)<=1{ + return true + } + dp:=make([]bool,len(nums)) + dp[0]=true + for i:=1;i=0;j--{ + if dp[j]&&nums[j]+j>=i{ + dp[i]=true + break + } + } + } + return dp[len(nums)-1] +} +```