goog 1: check continuous array.

existing an array, check the longest continuous sub-array. what if the array has 5 million elements.


class ArrayUtils {
	public:
		void checkContinue( int a[], n) {
				int max=-1;
				int count = 1;
				for(int i=1; i<n; i++) {
					if( a[i] == a[i-1] + 1 ) {
						count++;
					}  else {
						max = count>max ? count : max;
						count = 1;
					}
				}
				return max;
		} 
}


posted @ 2013-01-17 13:40  西施豆腐渣  阅读(139)  评论(0编辑  收藏  举报