LeetCode
Next Permutation
Click
here
for an explanation.