Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit17324b2

Browse files
committed
Fixed index out of bound error in rotated binary search with duplicates
1 parent9df5fb9 commit17324b2

File tree

1 file changed

+2
-2
lines changed
  • lectures/10-binary search/code/src/com/kunal

1 file changed

+2
-2
lines changed

‎lectures/10-binary search/code/src/com/kunal/RBS.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ static int findPivotWithDuplicates(int[] arr) {
8585
// skip the duplicates
8686
// NOTE: what if these elements at start and end were the pivot??
8787
// check if start is pivot
88-
if (arr[start] >arr[start +1]) {
88+
if (start <end &&arr[start] >arr[start +1]) {
8989
returnstart;
9090
}
9191
start++;
9292

9393
// check whether end is pivot
94-
if (arr[end] <arr[end -1]) {
94+
if (end >start &&arr[end] <arr[end -1]) {
9595
returnend -1;
9696
}
9797
end--;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp