I strongly recommend adding tougher test cases!


  • 1
    E

    Even though we have 188 test cases for this problem, none of them seems to be tough enough to fail the following O(n) solution. As usual, this can potentially mislead us because it got passed in 1ms and one might be thinking his solution is a very good one! I understand that the worst case for this problem is O(n), but having tougher test cases (not worst case) is still quite necessary.

    public int findMin(int[] nums) {
    	for(int i=1, L=nums.length; i<L; i++) {
    	    if(nums[i]<nums[i-1]) return nums[i];
    	}
    	return nums[0];
    }

Log in to reply
 

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