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

Commite243497

Browse files
add 1996
1 parent483e69d commite243497

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-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+
|1996|[The Number of Weak Characters in the Game](https://leetcode.com/problems/the-number-of-weak-characters-in-the-game/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1996.java)||Medium||
1112
|1995|[Count Special Quadruplets](https://leetcode.com/problems/count-special-quadruplets/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1995.java)||Easy||
1213
|1992|[Find All Groups of Farmland](https://leetcode.com/problems/find-all-groups-of-farmland/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1992.java)||Medium||
1314
|1991|[Find the Middle Index in Array](https://leetcode.com/problems/find-the-middle-index-in-array/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1991.java)||Easy||
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
packagecom.fishercoder.solutions;
2+
3+
importjava.util.Arrays;
4+
5+
publicclass_1996 {
6+
publicstaticclassSolution1 {
7+
publicintnumberOfWeakCharacters(int[][]properties) {
8+
intcount =0;
9+
/**sort them based on:
10+
* if attack values equal, then sort by defense value ascendingly
11+
* if not, sort by attack values descendingly.
12+
* */
13+
Arrays.sort(properties, (a,b) ->a[0] ==b[0] ?a[1] -b[1] :b[0] -a[0]);
14+
intmax =0;
15+
for (inti =0;i <properties.length;i++) {
16+
count +=max >properties[i][1] ?1 :0;
17+
max =Math.max(max,properties[i][1]);
18+
}
19+
returncount;
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp