连续子数组的最大和 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(){
		
	}
}

原文地址:https://www.cnblogs.com/yan456jie/p/5369412.html