From 1990277f20184013d1cf45e4ffff09d7d4d14279 Mon Sep 17 00:00:00 2001 From: AshishJainMSRIT Date: Sat, 23 Jan 2021 15:49:11 +0530 Subject: [PATCH] Update Question.java Since nums=[3,1,1], x=1 is also a valid test case for this problem. But currently, the output of the code is -1 as condition (a[left]==a[mid]) is false and there is not condition for (a[mid]==a[right]). So, I have removed this condition and it works fine in Leetcode. --- .../Q10_03_Search_in_Rotated_Array/Question.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Java/Ch 10. Sorting and Searching/Q10_03_Search_in_Rotated_Array/Question.java b/Java/Ch 10. Sorting and Searching/Q10_03_Search_in_Rotated_Array/Question.java index bf7fd82ae..3facc4a79 100644 --- a/Java/Ch 10. Sorting and Searching/Q10_03_Search_in_Rotated_Array/Question.java +++ b/Java/Ch 10. Sorting and Searching/Q10_03_Search_in_Rotated_Array/Question.java @@ -32,7 +32,7 @@ public static int search(int a[], int left, int right, int x) { } else { return search(a, left, mid - 1, x); } - } else if (a[left] == a[mid]) { // Left is either all repeats OR loops around (with the right half being all dups) + } else { // Left is either all repeats OR loops around (with the right half being all dups) if (a[mid] != a[right]) { // If right half is different, search there return search(a, mid + 1, right, x); } else { // Else, we have to search both halves