2014
11-19

# LeetCode-First Missing Positive[排序]

### First Missing Positive

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.

// LeetCode, First Missing Positive
// 时间复杂度O(n)，空间复杂度O(1)
class Solution {
public:
int firstMissingPositive(int A[], int n) {
bucket_sort(A, n);

for (int i = 0; i < n; ++i)
if (A[i] != (i + 1))
return i + 1;
return n + 1;
}
private:
static void bucket_sort(int A[], int n) {
for (int i = 0; i < n; i++) {
while (A[i] != i + 1) {
if (A[i] <= 0 || A[i] > n || A[i] == A[A[i] - 1])
break;
swap(A[i], A[A[i] - 1]);
}
}
}
};


1. Pingback: bondage straps

2. Pingback: robert

3. Pingback: pc games for windows 7

4. Pingback: pc apps for windows 8

5. Pingback: how to last longer

6. Pingback: end of lease clean Melbourne

7. Pingback: Sripatum university

8. Pingback: sex toys lubricant

9. Pingback: adam and eve sex toys

10. Pingback: Best Sex Lubricant

11. Pingback: Bondage Gear

12. Pingback: Super Head Honcho Masturbator

13. Pingback: Blue Dolphin Sex Toy

14. Pingback: Clit Sensitizer

15. Pingback: Magic Massager Deluxe

18. Pingback: g spot

20. Pingback: bandiere

21. Pingback: rental bond cleaning Melbourne

22. Pingback: adam and eve sex toy shop

23. Pingback: vibrator pink

24. Pingback: Bath Bombs

25. Pingback: suction cup dildo

26. Pingback: anal butt plug

27. Pingback: best vibrator

28. Pingback: butt plug

29. Pingback: butt plug

30. Pingback: gay toys

31. Pingback: vibrating butt plug

32. Pingback: Healthy food easy to prepare

33. Pingback: g spot

34. Pingback: label tudung

36. Pingback: vacuuming

38. Pingback: what is the importance of sex

41. Pingback: gold vibrator

42. Pingback: I Love News Paper

43. Pingback: Taoist Real Sex Talk

44. Pingback: real feel dildos

45. Pingback: best butt plug

47. Pingback: rabbit vibrator

48. Pingback: Venture Point Network

49. Pingback: web design company

50. Pingback: rampant vibrator

51. Pingback: COB led luminaries

52. Pingback: Duvet covers

53. Pingback: small glass jars

54. Pingback: basement remodeling in Atlanta

55. Pingback: scr3888

57. Pingback: foreplay sex toys

58. Pingback: triple vibrator

59. Pingback: luxury sex toys

60. Pingback: realistic vibrator

61. Pingback: womens sex toy

62. Pingback: best realistic dildo

63. Pingback: honey usa

64. Pingback: Jewelry

66. Pingback: tratamento Alcoolismo

69. Pingback: coffee’s best kona

70. Pingback: suction cup vibrating dildo

71. Pingback: ean code

72. Pingback: 2H2D

73. Pingback: pink rabbit sex toy

74. Pingback: sex toys for clit

76. Pingback: discount sex toys

77. Pingback: sex toys cleaner

78. Pingback: hands free sex toys

79. Pingback: sex toys for couples

80. Pingback: g-spot vibrators

81. Pingback: how can i make money online

82. Pingback: snuff bottles

83. Pingback: unique antiques

84. Pingback: leginy

86. Pingback: foldable wall bed

87. Pingback: lefkoşa satılık daire fiyatları

88. Pingback: Make Money Online

89. Pingback: robert

90. Pingback: barcode kaufen

91. Pingback: uk email lists

92. Pingback: Herbal Oils

93. Pingback: tratamento de drogas

94. Pingback: Double Sided Dildo

95. Pingback: work home opportunities

96. Pingback: masturbation

99. Pingback: pure kona

103. Thanks for using the time to examine this, I truly feel strongly about it and enjoy finding out far more on this subject matter. If achievable, as you achieve knowledge

104. Gucci New Fall Arrivals

This is really nice to know. I hope it will be successful in the future. Good job on this and keep up the good work.

105. 第一句可以忽略不计了吧。从第二句开始分析，说明这个花色下的所有牌都会在其它里面出现，那么还剩下♠️和♦️。第三句，可以排除2和7，因为在两种花色里有。现在是第四句，因为♠️还剩下多个，只有是♦️B才能知道答案。

106. 换句话说，A[k/2-1]不可能大于两数组合并之后的第k小值，所以我们可以将其抛弃。
应该是，不可能小于合并后的第K小值吧