solution to Next Permutation