连续子数组的最大和 java实现

package findMax;
/**
 * 连续子数组的最大和
 * @author root
 *
 */
public class FindMax {

	static int[] data = {1,-2,3,10,-4,7,2,-5};
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		find();
	}
	//分析数据规律
	public static void find(){
		int max = 0;
		int temp = 0;
		for(int i=0; i<data.length; i++){
			temp+=data[i];
			if(temp>max){
				max = temp;
			}
			if(temp<0){
				temp = 0;
			}
		}
		System.out.println(max);
	}
	//动态规划求解
	public static void findDongtai(){
		
	}
}

posted on 2016-03-05 13:44  长456风  阅读(580)  评论(0编辑  收藏  举报

导航