package com.test;
/**
* @ClassName HelloController
* @Description TODO
* @Author zengjx
* @Company zengjx
* @Date 2020/1/12 13:10
* @Version V1.0
*/
public class Solution47 {
static int[][] arr ={
{1,10,3,8} ,
{12,2,9,6},
{5,7,4,11},
{3,7,16,5}
};
public static void main(String[] args) {
System.out.println(getMax(arr));
}
public static int getMax(int[][] arr) {
int iCount = 0;
int i = 0, j = 0;
iCount=arr[0][0];
while (i < arr.length && j < arr[0].length)
{
if (i + 1 < arr.length && j + 1 < arr[0].length) {
System.out.println("i=" + i + " j " + j);
if (arr[i][j + 1] > arr[i + 1][j]) {
iCount += arr[i][j + 1];
j++;
} else {
iCount += arr[i + 1][j];
i++;
}
} else if (i + 1 < arr.length && j < arr[0].length) {
iCount += arr[i + 1][j];
System.out.println("i=" + i + " j " + j+"arr"+arr[i][j]);
i++;
} else if (j + 1 < arr[j].length && i < arr.length) {
iCount += arr[i][j + 1];
System.out.println("i=" + i + " j " + j);
j++;
} else {
System.out.println("i " + i + " j" + j);
}
if(i==arr.length-1 && j==arr[0].length-1){
break;
}
}
return iCount;
}
}
剑指offer第47 题礼物最大值
猜你喜欢
转载自blog.csdn.net/oDianZi1234567/article/details/103945705
今日推荐
周排行