Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf4c6b11

Browse files
add 2341
1 parent24e608d commitf4c6b11

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
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+
| 2341|[Maximum Number of Pairs in Array](https://leetcode.com/problems/maximum-number-of-pairs-in-array/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2341.java)|| Easy||
1112
| 2335|[Minimum Amount of Time to Fill Cups](https://leetcode.com/problems/minimum-amount-of-time-to-fill-cups/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2335.java)|| Easy||
1213
| 2331|[Evaluate Boolean Binary Tree](https://leetcode.com/problems/evaluate-boolean-binary-tree/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2331.java)|| Easy||
1314
| 2326|[Spiral Matrix IV](https://leetcode.com/problems/spiral-matrix-iv/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2326.java)|| Medium||
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
packagecom.fishercoder.solutions;
2+
3+
importjava.util.HashMap;
4+
importjava.util.Map;
5+
6+
publicclass_2341 {
7+
publicstaticclassSolution1 {
8+
publicint[]numberOfPairs(int[]nums) {
9+
Map<Integer,Integer>map =newHashMap<>();
10+
for (intnum :nums) {
11+
map.put(num,map.getOrDefault(num,0) +1);
12+
}
13+
intpairs =0;
14+
intleftover =0;
15+
for (intkey :map.keySet()) {
16+
if (map.get(key) >1) {
17+
pairs +=map.get(key) /2;
18+
leftover +=map.get(key) %2;
19+
}else {
20+
leftover++;
21+
}
22+
}
23+
returnnewint[]{pairs,leftover};
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp