C++ | Leetcode C++ 问题解决 Question 448 Find all the disappearing numbers in the array - Problem Solved:
最编程
2024-10-01 07:50:19
...
class Solution {
public:
vector<int> findDisappearedNumbers(vector<int>& nums) {
int n = nums.size();
for (auto& num : nums) {
int x = (num - 1) % n;
nums[x] += n;
}
vector<int> ret;
for (int i = 0; i < n; i++) {
if (nums[i] <= n) {
ret.push_back(i + 1);
}
}
return ret;
}
};
推荐阅读
-
简单 JSON 解析和转储的 C++ 实现
-
微服务开源框架 TARS RPC 源代码初识 TARS C++ 服务器端
-
LeetCode:计算满足 k 约束 I 的子串数量(滑动窗口 Java)
-
C++ 游戏开发:从基础到高级
-
opencv c++ 获取掩码的最大连接域方法
-
C++ 研发笔记 2 - 学习规划概述
-
LeetCode] 动态编程 - 95.动态编程 - 95.不同的二叉搜索树 II(附完整 Python/C++ 代码) - 基本思想
-
Conda] 解决在 Conda 中安装软件包时遇到的 "收集软件包元数据 "问题解决在 Conda 中安装软件包时遇到的 "收集软件包元数据 "问题 - 简介
-
LeetCode 问题练习和总结:二叉树的序列化和反序列化 - 297 - 输入:根 = [1,2] 输出: 根[1,2] 提示
-
C++ 中的 Initializer_list 类