Next Permutation Leetcode Solution 862 Heads