I strongly recommend adding tougher test cases!

  • 1

    Even though we have 146 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 have already seen O(n) solution posted here.

    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];

  • 0

    what case this solution should fail? thanks.

Log in to reply

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