GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — CodingInterview/Solution43.java at master · legolas007/CodingInterview

Expand file tree

/

Solution43.java

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
37 lines (36 loc) · 1.1 KB
/

Solution43.java

Copy path

File metadata and controls

37 lines (36 loc) · 1.1 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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.