• Welcome to the world's largest Chinese hacker forum

    Welcome to the world's largest Chinese hacker forum, our forum registration is open! You can now register for technical communication with us, this is a free and open to the world of the BBS, we founded the purpose for the study of network security, please don't release business of black/grey, or on the BBS posts, to seek help hacker if violations, we will permanently frozen your IP and account, thank you for your cooperation. Hacker attack and defense cracking or network Security

    business please click here: Creation Security  From CNHACKTEAM

Recommended Posts

包演示;

公共类P43 {

//乱序整型数组,元素为在用的id(从一开始),求最小空余可用编号

//思路1:创建(长度1)数组,下标对应id,id=长度且用过则值设为一

//思路2:用分区法,不断二分。如果下标1==id,说明左区和中间的都用过,再从右区找;否则说明左区有空余,再从左区找。

公共静态void main(String[] args) {

int[] arr={4,2,3,5,6,1 };

系统。出去。println(small estid(arr));

}

static int smallestId(int[] arr) {

int[]helper=new int[数组长度1];

for(int I=0;iarr。长度;i ) {

if(arr=arr.length) {

helper[arr]=1;

}

}

for(int I=1;我=数组长度;i ) {

if(helper==0) {

返回我;

}

}

返回数组长度1;

}

}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now