Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

剑指offer:字符串的排列,递归调用之后没有交换为原数组 #2

Open
Mrfuture1 opened this issue Mar 15, 2018 · 1 comment

Comments

@Mrfuture1
Copy link

  • 代码路径:coding-interviews/src/Test28.java
  • 代码:
tmp = chars[begin];
chars[begin] = chars[i];
chars[i] = tmp;
// 处理下一个位置
permutation(chars, begin + 1);
  • 修改
//permutation(chars, begin + 1);后添加代码:
tmp = chars[i];
chars[i] = chars[begin];
chars[begin] = tmp;
@songqiangchina
Copy link

是的,应该要做回溯,这样才能打印出正确结果;
另外,没有考虑字符重复的问题,比如“abb”,那么排列应该改成3种结果
建议加个set做一下重复过滤

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants