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

Commit182d6e3

Browse files
add 2239
1 parent73d5ecf commit182d6e3

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

‎README.md

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

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|------|----------------|------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|-------------|-------------
11-
| 2260|[Minimum Consecutive Cards to Pick Up](https://leetcode.com/problems/minimum-consecutive-cards-to-pick-up/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2260.java)|| Medium||
11+
| 2260|[Minimum Consecutive Cards to Pick Up](https://leetcode.com/problems/minimum-consecutive-cards-to-pick-up/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2260.java)|| Medium||
1212
| 2259|[Remove Digit From Number to Maximize Result](https://leetcode.com/problems/remove-digit-from-number-to-maximize-result/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2259.java)|| Easy||
1313
| 2256|[Minimum Average Difference](https://leetcode.com/problems/minimum-average-difference/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2256.java)|| Medium||
1414
| 2255|[Count Prefixes of a Given String](https://leetcode.com/problems/count-prefixes-of-a-given-string/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2255.java)|| Easy||
1515
| 2248|[Intersection of Multiple Arrays](https://leetcode.com/problems/intersection-of-multiple-arrays/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2248.java)|| Easy||
1616
| 2244|[Minimum Rounds to Complete All Tasks](https://leetcode.com/problems/minimum-rounds-to-complete-all-tasks/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2244.java)|| Medium||
1717
| 2243|[Calculate Digit Sum of a String](https://leetcode.com/problems/calculate-digit-sum-of-a-string/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2243.java)|| Easy||
18+
| 2239|[Find Closest Number to Zero](https://leetcode.com/problems/find-closest-number-to-zero/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2239.java)|| Easy||
1819
| 2220|[Minimum Bit Flips to Convert Number](https://leetcode.com/problems/minimum-bit-flips-to-convert-number/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2220.java)|| Easy||
1920
| 2215|[Find the Difference of Two Arrays](https://leetcode.com/problems/find-the-difference-of-two-arrays/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2215.java)|| Easy||
2021
| 2210|[Count Hills and Valleys in an Array](https://leetcode.com/problems/count-hills-and-valleys-in-an-array/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2210.java)|| Easy||
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
packagecom.fishercoder.solutions;
2+
3+
publicclass_2239 {
4+
publicstaticclassSolution1 {
5+
publicintfindClosestNumber(int[]nums) {
6+
intans =nums[0];
7+
intminDiff =Math.abs(nums[0]);
8+
for (inti =1;i <nums.length;i++) {
9+
intdiff =Math.abs(nums[i]);
10+
if (diff <minDiff) {
11+
minDiff =diff;
12+
ans =nums[i];
13+
}elseif (diff ==minDiff &&nums[i] >ans) {
14+
ans =nums[i];
15+
}
16+
}
17+
returnans;
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp