由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 问一道关于字符串的面试题
相关主题
string permutation,怎么处理重复字母?amazon onsite 面经
请教amazon面试题一个容易记忆的permutation算法
请教一个电话面试题String permunation question (CS)
请教一道面试题请问大牛们leetcode上的Permutations II
两道简单的面试题【Google字符串面试题】
一道amazon题分享一道最近碰到的很好的面试题。
一道C/C++的面试题马上要去G onsite了,求助个问题
一道面试题关于leetcode的Scramble String问题
相关话题的讨论汇总
话题: str话题: start话题: 字符
进入JobHunting版参与讨论
1 (共1页)
r******e
发帖数: 80
1
how to get all permutation of a string if there are duplications?
想了很久,想不出方法。 请大家看看有没有比较好的思路。
x*****p
发帖数: 1707
2
Using recursive for permutation, and put it into a set which automatically
remove duplicates, then output the set.
r******e
发帖数: 80
3
谢谢, xiongyp
1. 如果没有空间存在set里面呢?
2. 另外,对于n长度的字符串, 其中有m个相同的字符, 其它的都是唯一的。 复杂度
是 n!. 有没有办法做到 n! / m! 呢?
l*****a
发帖数: 14598
4
step1: sort input string
step2:
for(int i=start;i {
if(i!=start)&&(str[i]==str[i-1]) continue;
swap(str[i],str[start]);
func(i+1,str);
swap(str[i],str[start]);
}

【在 r******e 的大作中提到】
: how to get all permutation of a string if there are duplications?
: 想了很久,想不出方法。 请大家看看有没有比较好的思路。

i**9
发帖数: 351
5
讲讲原因?

【在 l*****a 的大作中提到】
: step1: sort input string
: step2:
: for(int i=start;i: {
: if(i!=start)&&(str[i]==str[i-1]) continue;
: swap(str[i],str[start]);
: func(i+1,str);
: swap(str[i],str[start]);
: }

f***g
发帖数: 214
6
仅仅判断(str[i]==str[i-1])
还不够
要看str[start]和str[i-1]之间有没有str[i]

【在 l*****a 的大作中提到】
: step1: sort input string
: step2:
: for(int i=start;i: {
: if(i!=start)&&(str[i]==str[i-1]) continue;
: swap(str[i],str[start]);
: func(i+1,str);
: swap(str[i],str[start]);
: }

x*****p
发帖数: 1707
7
1. 先用一个Hashtable统计每个字符出现的频率:(c_1, v_1), (c_2, v_2), ..., (c_
k, v_k)
2. 做一个长度为n的字符数组,填入c_1入v_1的位置,有C(n, v_1)种填法,每一种填
法,剩下的位置填入v_2个c_2,用递归算法填完后面所有的字符。
1 (共1页)
进入JobHunting版参与讨论
相关主题
关于leetcode的Scramble String问题两道简单的面试题
A 家两轮电话面试面经攒人品一道amazon题
脑子卡住了,谁帮我看看一道C/C++的面试题
大公司算法题一道面试题
string permutation,怎么处理重复字母?amazon onsite 面经
请教amazon面试题一个容易记忆的permutation算法
请教一个电话面试题String permunation question (CS)
请教一道面试题请问大牛们leetcode上的Permutations II
相关话题的讨论汇总
话题: str话题: start话题: 字符