e****9 发帖数: 316 | 1 刚刚amazon的电话,一道大题,求"abc"的多有组合。
之前准备了排列,没有看组合,结果就考了组合。
还是准备的不好。 | I**A 发帖数: 2345 | 2 递归就可以了。
我纠结递归有一阵儿了
所以编了一些程序
public static void combine( String instr ){
int length = instr.length();
StringBuilder outstr = new StringBuilder();
doCombine( instr, outstr, length, 0 );
}
public static void doCombine(String instr, StringBuilder outstr, int
length, int start ){
for( int i = start; i < length; i++ ){
outstr.append( instr.charAt(i) );
System.out.println( outstr );
if( i < length - 1 ){
【在 e****9 的大作中提到】 : 刚刚amazon的电话,一道大题,求"abc"的多有组合。 : 之前准备了排列,没有看组合,结果就考了组合。 : 还是准备的不好。
| l******c 发帖数: 2555 | 3 what's meaning of 组合?
{a} {a, b} .. {a, b, c} ???
【在 e****9 的大作中提到】 : 刚刚amazon的电话,一道大题,求"abc"的多有组合。 : 之前准备了排列,没有看组合,结果就考了组合。 : 还是准备的不好。
| v******k 发帖数: 808 | 4 this is really basic; better let ppl of better skill set get the job; | g*******y 发帖数: 1930 | 5 agree.
lz should get more preparation before wasting interview opportunity
【在 v******k 的大作中提到】 : this is really basic; better let ppl of better skill set get the job;
| A********l 发帖数: 184 | 6 似乎普通的二重循环就可以了。
for(int i = 0, n = instr.length(); i < n; i++) {
for (int j = i + 1; j <= n; j++) {
System.out.println(instr.subString(i, j));
}
}
【在 I**A 的大作中提到】 : 递归就可以了。 : 我纠结递归有一阵儿了 : 所以编了一些程序 : public static void combine( String instr ){ : int length = instr.length(); : StringBuilder outstr = new StringBuilder(); : doCombine( instr, outstr, length, 0 ); : } : public static void doCombine(String instr, StringBuilder outstr, int : length, int start ){
|
|