小工具知识网

当前位置: 首页 > 行业知识 > 第 125 场 LeetCode 双周赛题解

行业知识

第 125 场 LeetCode 双周赛题解

2026-11-05 06:23:26 来源:互联网转载

A 超过阈值的最少操作数 I

���序然后查找第一个大于等于 k 的元素所在的位置

class Solution {public:    int minOperations(vector &nums, int k) {        sort(nums.begin(), nums.end());        return lower_bound(nums.begin(), nums.end(), k) - nums.begin();    }};

B 超过阈值的最少操作数 II

模拟:用最小堆维护数组中的最小元素

class Solution {public:    int minOperations(vector &nums, int k) {        priority_queue heap;        for (auto x: nums)            heap.push(x);        int res = 0;        while (heap.size() > 1 && heap.top()  

C 在带权树网络中统计可连接服务器对数目

dfs:枚举 c c c ,以 c c c 的各邻接点为源点进行 d f s dfs dfs ,设各次 d f s dfs dfs 过程中路径和可以被 s i g n a l S p e e d signalSpeed signalSpeed 整除的节点数目为 a 1 , ⋯   , a k a_1,\cdots,a_k a1​,⋯,ak​,则通过 c c c 可连接的服务器对的数目为 ∑ 1 ≤ i

上一篇:利用JS、CSS实现列表自动滑动滚动

下一篇:linux上服务器挂了怎么处理?