Skip to content

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

@GarfieldCCC

Description

@GarfieldCCC
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条件中的判断条件改为>=和<=即可,我测试过,可以成功。
希望您可以采纳!!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions