---
title: "First Missing Positive"
author: "testforvln"
date: "2012-11-06T22:50:09Z"
tags: []
categories: ["编程语言"]
slug: "first-missing-positive"
draft: false
lastmod: "2012-11-06T22:50:09Z"
id: 1717828
url: "https://testforvln.iteye.com/blog/1717828"
---

唉 想了很久都没想出来 后来还是看了网上的答案 >_<
public class Solution {
    public int firstMissingPositive(int A) {
        // Start typing your Java solution below
        // DO NOT write main() function
 
        //put i to A, so the array looks like: 1, 2, 3, ...
 
        for (int i = 0; i < A.length; i++) {
            while (A* != i+1) {
                if (A* <= 0 || A* > A.length || A* == A - 1]) {
                    break;
                }
 
                int tmp = A-1];
                A-1] = A*;
                A* = tmp;
            }
        }
 
        for (int i = 0; i < A.length; i++) {
            if (A* != i+1) {
                return i+1;
            }
        }
        return A.length+1;
         
    }
}