题目链接:https://leetcode-cn.com/problems/relative-sort-array/
题目如下:
class Solution {
public int[] relativeSortArray(int[] arr1, int[] arr2) {
int i,j,temp,pos=0,num;
for(i=0;i<arr2.length;i++){
num=arr2[i];
for(j=pos;j<arr1.length;j++){
if(arr1[j]==num) {temp=arr1[pos];arr1[pos]=arr1[j];arr1[j]=temp;pos++;}
}
}
Arrays.sort(arr1,pos,arr1.length);//和注释部分一样的作用
/* for(i=pos;i<arr1.length-1;i++){
for(j=i+1;j<arr1.length;j++)
if(arr1[i]>arr1[j]) {temp=arr1[i];arr1[i]=arr1[j];arr1[j]=temp;}
}*/
return arr1;
}
}