GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — CodingInterview/Solution43.java at master · legolas007/CodingInterview Expand file tree/ Copy pathSolution43.javaMore file actions 37 lines (36 loc) · 1.1 KB / Copy pathSolution43.javaFile metadata and controls37 lines (36 loc) · 1.1 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 package com.usher.algorithm.offer; /** * @Author: Usher * @Description: * f[i][j]最大值 * f[i][j] = Math.max(f[i-1][j],f[i][j-1]) + grid[i][j]; * 上:f[i][j] = f[i-1][j] + grid[i][j]; * 左:f[i][j] = f[i][j-1] + grid[i][j]; * 初值:f[0][0] = grid[0][0] * f[0][j > 0] = f[0][j-1] + grid[0][j]//一行 * f[i > 0][ 0] = f[i-1][0] + grid[i][0]//一列 */ public class Solution43 { public int getMost(int[][] board) { // write code here int m = board.length; int n = board[0].length; int[][] f = new int[m+1][n+1]; for (int i =0;i < m;i++){ for (int j=0;j<n;j++){ if (i == 0){ if (j == 0){ f[i][j] = board[i][j]; }else { f[i][j] = f[i][j-1] + board[i][j]; } }else if (j == 0){ f[i][j] = f[i-1][j] + board[i][j]; }else { f[i][j] = Math.max(f[i-1][j],f[i][j-1]) + board[i][j]; } } } return f[m-1][n-1]; } } |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |