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

看了代码,有段不知道什么意思 #1

Open
jameschen4540 opened this issue Nov 2, 2018 · 1 comment
Open

看了代码,有段不知道什么意思 #1

jameschen4540 opened this issue Nov 2, 2018 · 1 comment

Comments

@jameschen4540
Copy link

/**
* 算法拆分组合 用1和0 的移位去做控制
* (这块需要你打印才能看的出来)
*
* @param len
* @param n
* @return
*/
private static ArrayList<Integer[]> getCombFlags(int len, int n) {
if (n <= 0) {
return new ArrayList<>();
}
ArrayList<Integer[]> aResult = new ArrayList<>();
Integer[] aFlag = new Integer[len];
boolean bNext = true;
int iCnt1 = 0;
//初始化
for (int i = 0; i < len; i++) {
aFlag[i] = i < n ? 1 : 0;
Log.e(TAG, "getCombFlags:初始化===aFlag["+i+"]== "+ aFlag[i]);
}

    aResult.add(aFlag.clone());
    while (bNext) {
        iCnt1 = 0;
        for (int i = 0; i < len - 1; i++) {
            if (aFlag[i] == 1 && aFlag[i + 1] == 0) {
                for (int j = 0; j < i; j++) {
                    aFlag[j] = j < iCnt1 ? 1 : 0;
                    Log.e(TAG, "getCombFlags:aFlag["+j+"]== "+ aFlag[j]);
                }
                aFlag[i] = 0;
                aFlag[i + 1] = 1;
                Integer[] aTmp = aFlag.clone();
                aResult.add(aTmp);
                if (!TextUtils.join("", aTmp).substring(len - n).contains("0")) {
                    bNext = false;
                }
                break;
            }
            if (aFlag[i] == 1) {
                iCnt1++;

            }
        }
    }
    Log.e(TAG, "getCombFlags:aResult=== "+aResult );
    return aResult;
}
@hfkai
Copy link
Owner

hfkai commented Nov 20, 2018

这段代码的意思是拆分sku的所有可能的组合,你可以试着一个一个打印出来看看

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