Search in Rotated Sorted Array Hard?the test cases are too weak.


  • 0
    T

    i pass it by writing like this below:

    public class Solution {
        public int search(int[] A, int target) {
              for (int i = 0; i < A.length; i++) {
                if (A[i] == target) return i;
    
            }
            return -1;
        }
    

    }


  • 0
    T

    the same as Search in Rotated Sorted Array II


  • 4
    S

    I'm pretty sure you don't want to use linear search as your final solution in your real interview, and therefore you shouldn't do so on OJ. It is techniquely hard to differentiate a O(logn) algorithm from an O(n) one, so please do not rely solely on the error-checking mechanism of OJ.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.