1738. 找出第 K 大的异或坐标值

1738. 找出第 K 大的异或坐标值


题目链接:1738. 找出第 K 大的异或坐标值

代码如下:

cpp 复制代码
//列前缀异或和
//参考链接:https://leetcode.cn/problems/find-kth-largest-xor-coordinate-value/solutions/2790359/liang-chong-fang-fa-er-wei-qian-zhui-yi-689bf
class Solution 
{
public:
    int kthLargestValue(vector<vector<int>>& matrix, int k) 
    {
        vector<int> res,col_sum(matrix[0].size());
        for(const auto& row:matrix)
        {
            int s=0;
            for(int j=0;j<row.size();j++)
            {
                col_sum[j]^=row[j];
                s^=col_sum[j];
                res.push_back(s);
            }
        }
        ranges::nth_element(res,res.end()-k);
        return res[res.size()-k];
    }
};
相关推荐
hPw0eKIqD5 小时前
C++ 模板参数推导问题小记(非推导上下文)
开发语言·c++
程序员爱德华6 小时前
Python与C++:异同点对比
c++·python
888CC++9 小时前
C语言与C++的区别:从面向过程到面向对象
java·c语言·c++
Darkwanderor10 小时前
Linux系统编程实战项目:模拟实现shell
linux·c++
himobrinehacken11 小时前
揭秘Windows程序启动的神秘之旅
c++·安全
库玛西11 小时前
C++ 运行时多态 :核心总结与原理图解
c语言·c++·笔记
Byron Loong12 小时前
【C++】重定向是什么
开发语言·c++
hansang_IR13 小时前
【题解】LC:Z 算法(Z Algorithm)
c++·算法·字符串
霍霍的袁15 小时前
【C++】模板从入门到进阶(函数模板 + 类模板 + 特化 + 分离编译)
开发语言·c++·visual studio
海清河晏11115 小时前
Qt 实战:信号与槽+事件系统
开发语言·c++·qt