题目:
此题暴力肯定超时,所以可以利用一些技巧。
先让第一位升序,然后第二位降序的方式,从后向前遍历,并记录遍历时候第1维的最大值,因为如果第1维的数据小于前面记录的最大值,就表示第0维已经符合条件,且第1维也符合条件,最后,一直更新第1维的最大值即可。
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26class Solution { public int numberOfWeakCharacters(int[][] properties) { int cnt=0; int len=properties.length; Arrays.sort(properties, new Comparator<int[]>(){ @Override public int compare(int[] a, int[] b){ if(a[0]!=b[0]) return a[0]-b[0]; return b[1]-a[1]; } }); int max = properties[len-1][1]; for(int i=len-1;i>=0;i--){ if(properties[i][1] < max){ cnt++; } max=Math.max(max,properties[i][1]); } return cnt; } }
最后
以上就是陶醉绿草最近收集整理的关于leecode5864,游戏中弱角色的数量的全部内容,更多相关leecode5864,游戏中弱角色内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复