Nice solution! Here comes the Java codes using your idea:

public void nextPermutation(int[] nums) {
if (nums == null || nums.length <= 1) return;
for (int i = nums.length - 2; i >= 0; i--) {
if (nums[i] < nums[i+1]) {
int min = nums[i+1], index = i + 1;
for (int j = i + 1; j < nums.length; j++) {
if (nums[j] < min && nums[j] > nums[i]) {
index = j;
min = nums[j];
}
}
nums[index] = nums[i];
nums[i] = min;
Arrays.sort(nums, i+1, nums.length);
return;
}
}
Arrays.sort(nums);
}