Could you help me why my c++ code can not pass the some cases?


  • 0
    L
    class Solution {
    public:
        int findMin(vector<int>& nums) {
        	int low,high,mid,mark;
        	low = 0;
        	high = nums.size()-1;
        	mark = high;//下标
        	while(low<=high){
        		if((low+1)==high){
        			int temp = nums[low]<nums[high]?low:high;
        			if(nums[temp]<nums[mark])
        				mark = temp;
        			break;
        		}
        		mid = low+(high-low)/2;
        		if(nums[low]<nums[mid]){
        			if(nums[low]<nums[mark])
        				mark = low;
        			low = mid+1;
        		}else if(nums[low]>nums[mid]){
        			if(nums[mid]<nums[mark])
        				mark = mid;
        			high = mid-1;
        		}else{
        			low++;
        		}
        	}//while
        	cout<<"mark="<<mark<<endl;
        	return nums[mark];
        }
    };

Log in to reply
 

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