Skip to content

The error about kthNumber #467

Open
Open
@Luffyying

Description

@Luffyying

Maybe the array in the test is a descending array,so the partition function should following like this:

function partition(arr, start, end) {
    let i = start;
    let pivot = arr[end];
    for (let j = start; j < end; j++) {
          if (arr[j] > pivot) {
               swap(arr, i, j);
                i += 1;
           }
     }
     swap(arr, i, end);
     return i;
}

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