[Find Minimum in Rotated Sorted Array II] why this code can be accepted?


  • 0
    E
    int findMin(int num[], int n) {
        int min = num[0];
        for(int i=0; i<n; i++){
            if(num[i] < min){
                min = num[i];
            }
        }
        return min;
    }
    
    I use this simple code to solve this problem, and it's accepted? no time exceed, I don't understand...

  • 0
    H

    Because the worst case of this question is O(n), I guess that's why it's accepted. But I think the interviewer would like to see binary search method at least on part of it.


Log in to reply
 

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