原地哈希。代码没怎么优化,思路清晰。

    int missingNumber(vector<int>& nums) {int size = nums.size();for (int i = 0; i < size; i++) {if (nums[i] != -1) {if (nums[i] == size) {nums.push_back(size);nums[i] = -1;}else if (i != nums[i]) {swap(nums[i], nums[nums[i]]);i--;  // 不前进的意思,由于上面i++}}}if (nums.size() != size + 1)return size;for (int i = 0; i <= size; i++)if (i != nums[i])return i;}

转载于:https://www.cnblogs.com/willaty/p/8430187.html

leetcode 268. Missing Number相关推荐

  1. LeetCode 268. Missing Number--Python解法--数学题

    LeetCode 268. Missing Number–Python解法–数学题 LeetCode题解专栏:LeetCode题解 LeetCode 所有题目总结:LeetCode 所有题目总结 大部 ...

  2. 268. Missing Number

    Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missin ...

  3. 268. Missing Number(缺失数字)

    题目地址:https://leetcode.com/problems/missing-number/description/ Given an array containing n distinct ...

  4. Leet Code OJ 268. Missing Number [Difficulty: Medium]

    题目: Given an array containing n distinct numbers taken from 0, 1, 2, -, n, find the one that is miss ...

  5. LeetCode之Missing Number

    1.题目 Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is m ...

  6. 268 missing number

    问题:给定一个包含n个不同数字的数组,从0开始,例如0,1,2,-n.找到数组中缺了那个数字.例如输入nums=[0,1,3],输出2. 思路:高斯 从0到n的和为sum=(1+n)*n/2.只要计算 ...

  7. PAT甲级1144 The Missing Number:[C++题解]哈希表

    文章目录 题目分析 题目链接 题目分析 来源:acwing 分析: 把所有的数放进一个hash表,然后从1开始遍历,看每个数是不是在hash表中,输出第一个不在表中的元素. ac代码 #include ...

  8. LeetCode:Largest Number - 求整型数组中各元素可拼合成的最大数字

    2019独角兽企业重金招聘Python工程师标准>>> 1.题目名称 Largest Number(求整型数组中各元素可拼合成的最大数字) 2.题目地址 https://leetco ...

  9. 【整数转字符串】LeetCode 9. Palindrome Number

    LeetCode 9. Palindrome Number Solution1: 不利用字符串 class Solution { public:bool isPalindrome(int x) {if ...

最新文章

  1. 艾伟_转载:深入研究 Repeater
  2. node python 速度_Java,Node,Python 运行速度比较
  3. 谷爱凌的父亲不是谷歌5号员工,但母亲一家都是高学历的运动健将
  4. Struts拦截器使用
  5. Vue中定义全局变量与常量的各种方式详解_vue.js_脚本之家
  6. 20172329 2017-2018-2 《程序设计与数据结构》实验一报告
  7. SDN 前提知识:关于东西南北向接口
  8. flex布局实现叠在另一个div之上_CSS3 flex弹性伸缩布局[上]
  9. Pycharm2019版中打开.md .st文件出现卡死情况怎么办?
  10. 如何处理Spring、Ibatis结合MySQL数据库使用时的事务操作
  11. graphpad做饼图_3D 饼环图初步完成
  12. 曾经如日中天的VB编程,现已没落,而惨遭嫌弃的它,成了香饽饽
  13. 网络基础知识之报文格式介绍
  14. msdn原版系统和原版office
  15. 关于图像融合 视频融合
  16. SIGIR20|LightGCN: Simplifying and Powering Graph Convolution Network for Recommendation
  17. 了解cuda和显卡等基本概念
  18. 爬虫代理和验证码识别
  19. Java工具集-MD5加密工具
  20. JWT JWS JWE

热门文章

  1. 内部体验腾讯负载均衡的新功能
  2. windows 10 常用快捷键
  3. 使用TortoiseGit处理代码冲突
  4. [Objective-C]OC中字典基本概念和常用方法(NSDictionary和NSMutableDictionary)
  5. 《笑谈银行IT》—畅谈“银行IT系统”
  6. Java判断文件类型
  7. 我的世界java版gamemode指令_我的世界切换生存和创造模式的命令是什么?
  8. .sh文件是什么语言_shell命令在C语言程序中的调用
  9. Python练习3-XML-RPC实现简单的P2P文件共享
  10. C语言经典例11-斐波那契数列