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

Commit0d31b5a

Browse files
[LEET-3386] add 3386
1 parente3f477d commit0d31b5a

File tree

3 files changed

+86
-0
lines changed
  • paginated_contents/algorithms/4th_thousand
  • src

3 files changed

+86
-0
lines changed

‎paginated_contents/algorithms/4th_thousand/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
|------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|------------|----------------------------------------------------------------------
33
| 3396|[Minimum Number of Operations to Make Elements in Array Distinct](https://leetcode.com/problems/minimum-number-of-operations-to-make-elements-in-array-distinct/)|[Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3396.java)|| Easy|
44
| 3392|[Count Subarrays of Length Three With a Condition](https://leetcode.com/problems/count-subarrays-of-length-three-with-a-condition/)|[Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3392.java)|| Easy|
5+
| 3386|[Button with Longest Push Time](https://leetcode.com/problems/button-with-longest-push-time/)|[Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3386.java)|| Easy|
56
| 3379|[Transformed Array](https://leetcode.com/problems/transformed-array/)|[Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3379.java)|| Easy|
67
| 3375|[Minimum Operations to Make Array Values Equal to K](https://leetcode.com/problems/minimum-operations-to-make-array-values-equal-to-k/)|[Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3375.java)|| Easy|
78
| 3370|[Smallest Number With All Set Bits](https://leetcode.com/problems/smallest-number-with-all-set-bits/)|[Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3370.java)|| Easy|
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
packagecom.fishercoder.solutions.fourththousand;
2+
3+
importjava.util.HashMap;
4+
importjava.util.Map;
5+
6+
publicclass_3386 {
7+
publicstaticclassSolution1 {
8+
publicintbuttonWithLongestTime(int[][]events) {
9+
Map<Integer,Integer>map =newHashMap<>();
10+
intans =events[0][0];
11+
map.put(events[0][0],events[0][1]);
12+
for (inti =1;i <events.length;i++) {
13+
intduration =events[i][1] -events[i -1][1];
14+
if (map.getOrDefault(events[i][0],0) <duration) {
15+
map.put(events[i][0],duration);
16+
}
17+
}
18+
intmaxDuration =events[0][1];
19+
for (Map.Entry<Integer,Integer>entry :map.entrySet()) {
20+
if (entry.getValue() >maxDuration) {
21+
ans =entry.getKey();
22+
maxDuration =entry.getValue();
23+
}elseif (entry.getValue() ==maxDuration) {
24+
if (entry.getKey() <ans) {
25+
ans =entry.getKey();
26+
}
27+
}
28+
}
29+
returnans;
30+
}
31+
}
32+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
packagecom.fishercoder.fourththousand;
2+
3+
importstaticorg.junit.jupiter.api.Assertions.assertEquals;
4+
5+
importcom.fishercoder.common.utils.CommonUtils;
6+
importcom.fishercoder.solutions.fourththousand._3386;
7+
importorg.junit.jupiter.api.BeforeEach;
8+
importorg.junit.jupiter.api.Test;
9+
10+
publicclass_3386Test {
11+
private_3386.Solution1solution1;
12+
13+
@BeforeEach
14+
publicvoidsetup() {
15+
solution1 =new_3386.Solution1();
16+
}
17+
18+
@Test
19+
publicvoidtest1() {
20+
assertEquals(
21+
1,
22+
solution1.buttonWithLongestTime(
23+
CommonUtils.convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray(
24+
"[1,2],[2,5],[3,9],[1,15]")));
25+
}
26+
27+
@Test
28+
publicvoidtest2() {
29+
assertEquals(
30+
2,
31+
solution1.buttonWithLongestTime(
32+
CommonUtils.convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray(
33+
"[9,4],[19,5],[2,8],[3,11],[2,15]")));
34+
}
35+
36+
@Test
37+
publicvoidtest3() {
38+
assertEquals(
39+
2,
40+
solution1.buttonWithLongestTime(
41+
CommonUtils.convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray(
42+
"[7,1],[19,3],[9,4],[12,5],[2,8],[15,10],[18,12],[7,14],[19,16]")));
43+
}
44+
45+
@Test
46+
publicvoidtest4() {
47+
assertEquals(
48+
16,
49+
solution1.buttonWithLongestTime(
50+
CommonUtils.convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray(
51+
"[5,5],[16,17],[16,19]")));
52+
}
53+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp