My code is shown below:
public class Solution {
public void nextPermutation(int[] nums) {
int k = 0;
for(int i = nums.length -1; i> 0 ;i--){
if(nums[i-1] < nums[i]){
k = i-1;
break;
}
}
if( k == 0) {Arrays.sort(nums); return;}
int tmp = nums[k];
nums[k] = nums[nums.length - 1];
nums[nums.length-1] = tmp;
Arrays.sort(nums,k+1,nums.length,new Comparator<Integer>(){
public int compare(Integer a, Integer b){
return b - a;
}
});
}
}
I want to sort the array in decreasing order by using comparator, but it always shows
Line 14: error: no suitable method found for sort(int[],int,int, anonymous Comparator)
Can anyone point out where is the problem? Thanks a lot!