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

如果数组中出现重复的元素,您的代码将无法执行 #2

Open
GarfieldCCC opened this issue Oct 19, 2018 · 0 comments
Open

Comments

@GarfieldCCC
Copy link

public int getMiddle(int[] list, int low, int high) {
        int temp = list[low];
        while(low < high) {
            while(low < high && list[high] >= temp) high--;
            list[low] = list[high];
            while(low < high && list[low] <= temp) low++;
            list[high] = list[low];
        }
        list[low] = temp;
        return low;
    }

如上,我认为只需要将while条件中的判断条件改为>=和<=即可,我测试过,可以成功。
希望您可以采纳!!

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

1 participant