Skip to content

Commit b1fd761

Browse files
authored
Update FindKthLargest.java
Fix random pivot
1 parent e77e8c0 commit b1fd761

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

‎algorithms/src/main/java/com/baeldung/algorithms/kthlargest/FindKthLargest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public int findKthElementByRandomizedQuickSelect(Integer[] arr, int left, int ri
9898

9999
private int randomPartition(Integer arr[], int left, int right) {
100100
int n = right - left + 1;
101-
int pivot = (int) (Math.random()) % n;
101+
int pivot = (int) (Math.random() * n);
102102
swap(arr, left + pivot, right);
103103
return partition(arr, left, right);
104104
}

0 commit comments

Comments
 (0)