-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add solutions to lc problems: No.2956,2957 (#2077)
* No.2956.Find Common Elements Between Two Arrays * No.2957.Remove Adjacent Almost-Equal Characters
- Loading branch information
Showing
14 changed files
with
485 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
solution/2900-2999/2956.Find Common Elements Between Two Arrays/Solution.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class Solution { | ||
public: | ||
vector<int> findIntersectionValues(vector<int>& nums1, vector<int>& nums2) { | ||
int s1[101]{}; | ||
int s2[101]{}; | ||
for (int& x : nums1) { | ||
s1[x] = 1; | ||
} | ||
for (int& x : nums2) { | ||
s2[x] = 1; | ||
} | ||
vector<int> ans(2); | ||
for (int& x : nums1) { | ||
ans[0] += s2[x]; | ||
} | ||
for (int& x : nums2) { | ||
ans[1] += s1[x]; | ||
} | ||
return ans; | ||
} | ||
}; |
18 changes: 18 additions & 0 deletions
18
solution/2900-2999/2956.Find Common Elements Between Two Arrays/Solution.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
func findIntersectionValues(nums1 []int, nums2 []int) []int { | ||
s1 := [101]int{} | ||
s2 := [101]int{} | ||
for _, x := range nums1 { | ||
s1[x] = 1 | ||
} | ||
for _, x := range nums2 { | ||
s2[x] = 1 | ||
} | ||
ans := make([]int, 2) | ||
for _, x := range nums1 { | ||
ans[0] += s2[x] | ||
} | ||
for _, x := range nums2 { | ||
ans[1] += s1[x] | ||
} | ||
return ans | ||
} |
20 changes: 20 additions & 0 deletions
20
solution/2900-2999/2956.Find Common Elements Between Two Arrays/Solution.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class Solution { | ||
public int[] findIntersectionValues(int[] nums1, int[] nums2) { | ||
int[] s1 = new int[101]; | ||
int[] s2 = new int[101]; | ||
for (int x : nums1) { | ||
s1[x] = 1; | ||
} | ||
for (int x : nums2) { | ||
s2[x] = 1; | ||
} | ||
int[] ans = new int[2]; | ||
for (int x : nums1) { | ||
ans[0] += s2[x]; | ||
} | ||
for (int x : nums2) { | ||
ans[1] += s1[x]; | ||
} | ||
return ans; | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
solution/2900-2999/2956.Find Common Elements Between Two Arrays/Solution.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class Solution: | ||
def findIntersectionValues(self, nums1: List[int], nums2: List[int]) -> List[int]: | ||
s1, s2 = set(nums1), set(nums2) | ||
return [sum(x in s2 for x in nums1), sum(x in s1 for x in nums2)] |
18 changes: 18 additions & 0 deletions
18
solution/2900-2999/2956.Find Common Elements Between Two Arrays/Solution.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
function findIntersectionValues(nums1: number[], nums2: number[]): number[] { | ||
const s1: number[] = Array(101).fill(0); | ||
const s2: number[] = Array(101).fill(0); | ||
for (const x of nums1) { | ||
s1[x] = 1; | ||
} | ||
for (const x of nums2) { | ||
s2[x] = 1; | ||
} | ||
const ans: number[] = Array(2).fill(0); | ||
for (const x of nums1) { | ||
ans[0] += s2[x]; | ||
} | ||
for (const x of nums2) { | ||
ans[1] += s1[x]; | ||
} | ||
return ans; | ||
} |
Oops, something went wrong.