forked from damaohongtu/JavaInterview
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMySolution.java
More file actions
49 lines (47 loc) · 1.12 KB
/
MySolution.java
File metadata and controls
49 lines (47 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package ALiBaBa;
import org.junit.Test;
/**
* @Author MaoTian
* @Classname MySolution
* @Description TODO
* @Date 下午4:50 2019/8/19
* @Version 1.0
* @Created by mao<[email protected]>
*/
public class MySolution {
public int partition(int[] nums,int value){
//
int pos=0;
int position=0;
for(int i=0;i<nums.length;i++){
if(nums[i]==value){
position=i;
break;
}
}
int num=nums[0];
nums[0]=nums[position];
nums[position]=num;
for(int i=0;i<nums.length;i++){
if(nums[i]<value){
pos++;
if(nums[i]<value&&pos<nums.length){
int tmp=nums[pos];
nums[pos]=nums[i];
nums[i]=tmp;
}
}
}
nums[0]=nums[pos];
nums[pos]=value;
return pos;
}
@Test
public void check(){
int[] nums={1,2,7,9,3,4,5,10,8};
partition(nums,8);
for (int i = 0; i <nums.length ; i++) {
System.out.println(nums[i]);
}
}
}