LeetCode Array Easy 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 others appear once.
Find all the elements of [1, n] inclusive that do not appear in this array.
Could you do it without extra space and in O(n) runtime? You may assume the returned list does not count as extra space.
Example:
Input:
[,,,,,,,] Output:
[,]
问题描述:给定一个数组,1 ≤ a[i] ≤ n (n为数据的长度) 数组中有的元素出现一次,有的出现两次,找到数组中没有出现的元素
思路:先遍历一遍做标记,然后再遍历一次,找到没有出现的元素
public IList<int> FindDisappearedNumbers(int[] nums) {
//Array.Sort(nums);
IList<int> res = new List<int>();
for(int i = ; i < nums.Length; i++){
int index = Math.Abs(nums[i])-;
if(nums[index] > ){
nums[index] = - * nums[index];
}
}
for(int i = ; i < nums.Length; i++){
if(nums[i] > ){
res.Add(i+);
}
}
return res;
}
LeetCode Array Easy 448. Find All Numbers Disappeared in an Array的更多相关文章
- [LeetCode&Python] Problem 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】448. Find All Numbers Disappeared in an Array
problem 448. Find All Numbers Disappeared in an Array solution: class Solution { public: vector<i ...
- 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 448. Find All Numbers Disappeared in an Array -easy (重要)
题目链接: https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array/description/ 题目描述: Give ...
- LeetCode 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 ...
- LeetCode: 448 Find All Numbers Disappeared in an Array(easy)
题目: Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice an ...
随机推荐
- java并发学习--第四章 JDK提供的线程原子性操作工具类
在了解JDK提供的线程原子性操作工具类之前,我们应该先知道什么是原子性:在多线程并发的条件下,对于变量的操作是线程安全的,不会受到其他线程的干扰.接下来我们就学习JDK中线程的原子性操作. 一.CAS ...
- JavaWeb(八):Filter和Listener
一.Filter 1.1 概述 Filter 的基本功能是对 Servlet 容器调用 Servlet 的过程进行拦截,从而在 Servlet 进行响应处理的前后实现一些特殊的功能.在 Servlet ...
- linux常用基本命令 grep awk 待优化
查看centos操作系统版本:cat /etc/centos-release 切换到当前用户主目录:cd 或者cd ~ 创建文件夹/a/b/c:mkdir -pv /a/b/c.如果/a/b/c的父目 ...
- 20180708-Java修饰符
public class className{ //...} private boolean myFlag;static final double weeks = 9.5;protected stat ...
- Strassen __128int
题目链接 题意思路很简单,递归求最小就好了.但__128int没见过.故写博客记下.__128int如果输入输出就要自己写函数. #include<bits/stdc++.h> using ...
- The Factor
The Factor Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- linux用setup命令来更改ip配置
在有安装系统桌面情况下,可以使用图形化形式来配置ip地址, 在命令行下,输入“setup”调出网卡.防火墙等配置界面: 2 选择“network configuration“,回车: 选择“devic ...
- 如何在微信小程序中使用iconfont
开篇废话 开发过小程序的童鞋肯定都会遇到这样的问题,当我们在小程序中使用iconfont官方推荐的方法插入字体时,我们总会得到一个打印机(滑稽).那么如何在小程序中正确的使用iconfont呢? 一. ...
- 最长上升子序列(LIS)动态规划
最长上升子序列 给你n个整数 A1 A2 ········· An 找出在这个数组里面的最长上升的子序列.例如给你(1,7,3,5,9,4,8),他的上升子序列有(1,7) (3,4,8)等等之类的, ...
- webpack 常用配置
webpack.config.js const path = require('path'); const webpack = require('webpack'); const htmlWebpac ...