leetcode permutation sequence refactoring