private void permute(List<String> res, String cur, List<Character> list, String center) {
        if (cur.length() == list.size()) {
            StringBuilder sb = new StringBuilder(cur);
            res.add(cur + center + sb.reverse().toString());
        } else {
            for (int i = 0; i < list.size(); ++i) {
                Character ch = list.get(i);
                if (ch == null) continue;
                list.set(i, null);
                permute(res, cur + ch, list, center);
                list.set(i, ch);
                while (i < list.size() - 1 && list.get(i) == list.get(i + 1)) ++i;
            }
        }
    }