Skip to content

Commit e243497

Browse files
add 1996
1 parent 483e69d commit e243497

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

README.md

+1
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||
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.Arrays;
4+
5+
public class _1996 {
6+
public static class Solution1 {
7+
public int numberOfWeakCharacters(int[][] properties) {
8+
int count = 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+
int max = 0;
15+
for (int i = 0; i < properties.length; i++) {
16+
count += max > properties[i][1] ? 1 : 0;
17+
max = Math.max(max, properties[i][1]);
18+
}
19+
return count;
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)