【Leetcode】First Missing Positive.pdfVIP

  • 15
  • 0
  • 约3.39千字
  • 约 3页
  • 2017-09-16 发布于浙江
  • 举报
为为梦梦起起航航 不不积积小小流流无无以以成成江江海海 【【LLeeeettccooddee】】FFiirrsstt MMiissssiinngg PPoossiittiivvee 类: leetcode 2013-12-17 20:27 144人阅读 评论 (0) 收藏 举报 leetcodeFirst Missing Positi Given an unsorted integer array, find the first missing positive integer. For example, Given [1,2,0] return 3, and [3,4,-1,1] return 2. Your algorithm should run in O(n) time and uses constant space. 题意:计算第一个未出现的正整数。 用hash存储,当数字出现,将对应的位置为true,但是有几点要注意: 1)由于正整数由1开始,而数组下标由0开始,所以设hash大小为n 2, 目的 是多容纳0和数组中所有数字都是正整数且不重复的情况,这是要求的值肯定 是n 1,考虑到最多需要保存n 2个数字,所以大小设为n 2. class Solution { public:

文档评论(0)

1亿VIP精品文档

相关文档