【leetcode】448. Find All Numbers Disappeared in an Array
problem
448. Find All Numbers Disappeared in an Array
solution:
class Solution {
public:
vector<int> findDisappearedNumbers(vector<int>& nums) {
vector<int> res;
for(int i=; i<nums.size(); i++)
{
int tmp = abs(nums[i]) - ;
nums[tmp] = nums[tmp]> ? -nums[tmp] : nums[tmp];
}
for(int i=; i<nums.size(); i++)
{
if(nums[i]>) res.push_back(i+);
}
return res;
}
};
参考
1. Leetcode_448. Find All Numbers Disappeared in an Array;
2. GrandYang;
完
【leetcode】448. Find All Numbers Disappeared in an Array的更多相关文章
- 【LeetCode】448. Find All Numbers Disappeared in an Array 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 方法一:暴力求解 方法二:原地变负做标记 方法三:使用set ...
- [leetcode]python 448. Find All Numbers Disappeared in an Array
Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and ot ...
- 448. Find All Numbers Disappeared in an Array【easy】
448. Find All Numbers Disappeared in an Array[easy] Given an array of integers where 1 ≤ a[i] ≤ n (n ...
- 【LeetCode】165. Compare Version Numbers 解题报告(Python)
[LeetCode]165. Compare Version Numbers 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博 ...
- leetcode 217. Contains Duplicate 287. Find the Duplicate Number 442. Find All Duplicates in an Array 448. Find All Numbers Disappeared in an Array
后面3个题都是限制在1-n的,所有可以不先排序,可以利用巧方法做.最后两个题几乎一模一样. 217. Contains Duplicate class Solution { public: bool ...
- 448. Find All Numbers Disappeared in an Array&&645. Set Mismatch
题目: 448. Find All Numbers Disappeared in an Array Given an array of integers where 1 ≤ a[i] ≤ n (n = ...
- 448. Find All Numbers Disappeared in an Array@python
Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and ot ...
- LeetCode算法题-Find All Numbers Disappeared in an Array(Java实现)
这是悦乐书的第232次更新,第245篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第99题(顺位题号是448).给定一个整数数组,其中1≤a[i]≤n(n =数组的大小) ...
- 【LeetCode】445. Add Two Numbers II 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 先求和再构成列表 使用栈保存节点数字 类似题目 日期 ...
随机推荐
- Python 类的式列化过程解剖
类的是劣化过程解剖 类的语法 class Dog(object): print("hello,I am a dog!") d = Dog() #实例化这个类 #此时的d就是类Dog ...
- Weighted Quick Union
Weighted Quick Union即: 在Quick Union的基础上对结点加权(weighted),在parent[i]基础上增加一个size[i]. 用来存储该结点(site)的所有子结点 ...
- loj6068. 「2017 山东一轮集训 Day4」棋盘 二分图,网络流
loj6068. 「2017 山东一轮集训 Day4」棋盘 链接 https://loj.ac/problem/6068 思路 上来没头绪,后来套算法,套了个网络流 经典二分图 左边横,右边列 先重新 ...
- Mysql中 in or exists not exists not in区别 (网络整理)
in 和or区别: 如果in和or所在列有索引或者主键的话,or和in没啥差别,执行计划和执行时间都几乎一样. 如果in和or所在列没有 索引的话,性能差别就很大了.在没有索引的情况下,随着in或者o ...
- TestNG详解(单元测试框架)
一.TestNG的优点 1.1 漂亮的HTML格式测试报告 1.2 支持并发测试 1.3 参数化测试更简单 1.4 支持输出日志 1.5 支持更多功能的注解 二.编写TestNG测试用例的步骤 2.1 ...
- HBase Region 各个状态的转换
Region 各个状态的转换 HBase 维护了每个 region 的一个状态信息,并保存在 hbase:meta 中.hbase:meta 本身region的状态信息被持久化到 ZooKeeper. ...
- HBuild 连接苹果手机
PC.苹果手机.数据线 1.在电脑端安装iTunes,安装完成之后提示重启. 2.用数据线连接苹果手机 PC 3.打开HBuild 菜单栏 --> 运行 --> 真机 ...
- mysql 主从配置,主-》windows,从-》centos6.5
1.虚拟机配置的主从关系.win7 ip地址192.168.52.102,虚拟机ip 192.168.184.128.docs进入主服务器(master)mysql目录下,添加用户,然后执行mysql ...
- ionic框架使用步骤
nodejs下载:https://npm.taobao.org/mirrors/node一.全局安装ionic: npm install -g cordova ionic 如果安装失败: npm in ...
- 二十五. Python基础(25)--模块和包
二十五. Python基础(25)--模块和包 ● 知识框架 ● 模块的属性__name__ # my_module.py def fun1(): print("Hello& ...