栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

LeetCode 1996. 游戏中弱角色的数量*

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

LeetCode 1996. 游戏中弱角色的数量*

具体思路:

之前见过一道原题;

卡在了单调栈上的第二维度排序上;

具体代码: 1.单调栈:
class Solution {
public:
    int numberOfWeakCharacters(vector>& properties) {
        int n=properties.size();
        vectorarr;
        sort(properties.begin(),properties.end(),[](vector& a,vector& b){
            if(a[0]==b[0])
                return a[1]>b[1];
            else
                return a[0]st;
        int cnt=0;
        for(int i=0;i
2.排序方法:
class Solution {
public:
    int numberOfWeakCharacters(vector>& properties) {
        int n=properties.size();
        vectorarr;
        sort(properties.begin(),properties.end(),[](vector& a,vector& b){
            if(a[0]==b[0])
                return a[1]b[0];
        });
        int maxdef=0;
        int cnt=0;
        for(int i=0;iproperties[i][1]){
                cnt++;
            }
            maxdef=max(maxdef,properties[i][1]);
        }
        return cnt;
    }
};
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/960322.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号