程序员面试100题之四十二,旋转数组的最小元素

// 100_42.cpp : Defines the entry point for the console application.

//



#include "stdafx.h"



int find(int * arr, int left, int right)

{

	if(left==right-1)

		return arr[right];

	int mid = (left+right)/2;

	if(arr[mid] > arr[left])

	{

		return find(arr,mid,right);

	}

	else

	{

		return find(arr,left,mid);

	}

}



int _tmain(int argc, _TCHAR* argv[])

{

	int arr[] = {3,4,1};

	printf("%d\n",find(arr,0,2));

	return 0;

}



你可能感兴趣的:(程序员)