8000 add 2540 · gaurangi99/Leetcode@b7f0e20 · GitHub
[go: up one dir, main page]

Skip to content

Commit b7f0e20

Browse files
add 2540
1 parent 9e96865 commit b7f0e20

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|------|----------------|------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|----------------------------------|-------------
11+
| 2540 |[Minimum Common Value](https://leetcode.com/problems/minimum-common-value/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2540.java) || Easy |
1112
| 2536 |[Increment Submatrices by One](https://leetcode.com/problems/increment-submatrices-by-one/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2536.java) || Medium |
1213
| 2535 |[Difference Between Element Sum and Digit Sum of an Array](https://leetcode.com/problems/difference-between-element-sum-and-digit-sum-of-an-array/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2535.java) || Easy |
1314
| 2530 |[Maximal Score After Applying K Operations](https://leetcode.com/problems/maximal-score-after-applying-k-operations/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2530.java) | [:tv:](https://youtu.be/nsOipmYbRlc) | Medium |
@@ -1335,7 +1336,7 @@ _If you like this project, please leave me a star._ ★
13351336
| 60 |[Permutation Sequence](https://leetcode.com/problems/permutation-sequence/)| [Solution](../master/src/main/java/com/fishercoder/solutions/_60.java) || Medium | Math, Backtracking
13361337
| 59 |[Spiral Matrix II](https://leetcode.com/problems/spiral-matrix-ii/)| [Solution](../master/src/main/java/com/fishercoder/solutions/_59.java) | [:tv:](https://www.youtube.com/watch?v=Sv9DK2C4rtc) | Medium |
13371338
| 58 |[Length of Last Word](https://leetcode.com/problems/length-of-last-word/)| [Solution](../master/src/main/java/com/fishercoder/solutions/_58.java) || Easy |
1338-
| 57 |[Insert Intervals](https://leetcode.com/problems/insert-interval/)| [Solution](../master/src/main/java/com/fishercoder/solutions/_57.java) |[:tv:](https://youtu.be/gDVb3R4onIM)| Medium | Array, Sort
1339+
| 57 |[Insert Intervals](https://leetcode.com/problems/insert-interval/)| [Solution](../master/src/main/java/com/fishercoder/solutions/_57.java) | [:tv:](https://youtu.be/gDVb3R4onIM) | Medium | Array, Sort
13391340
| 56 |[Merge Intervals](https://leetcode.com/problems/merge-intervals/)| [Solution](../master/src/main/java/com/fishercoder/solutions/_56.java) || Medium | Array, Sort
13401341
| 55 |[Jump Game](https://leetcode.com/problems/jump-game/)| [Solution](../master/src/main/java/com/fishercoder/solutions/_55.java) || Medium | Greedy
13411342
| 54 |[Spiral Matrix](https://leetcode.com/problems/spiral-matrix/)| [Solution](../master/src/main/java/com/fishercoder/solutions/_54.java) | [:tv:](https://www.youtube.com/watch?v=uYgoo8BdUAA) | Medium | Array
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.HashSet;
4+
import java.util.Set;
5+
6+
public class _2540 {
7+
public static class Solution1 {
8+
public int getCommon(int[] nums1, int[] nums2) {
9+
Set<Integer> set1 = new HashSet<>();
10+
for (int num : nums1) {
11+
set1.add(num);
12+
}
13+
Set<Integer> set2 = new HashSet<>();
14+
for (int num : nums2) {
15+
set2.add(num);
16+
}
17+
int result = -1;
18+
for (int num : nums1) {
19+
if (set2.contains(num)) {
20+
result = num;
21+
break;
22+
}
23+
}
24+
for (int num : nums2) {
25+
if (set1.contains(num) && result > num) {
26+
result = num;
27+
break;
28+
}
29+
}
30+
return result;
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)
0