pull/6/head
yuanguangxin 4 years ago
parent cded4a22b7
commit 4bca22a759

@ -2,7 +2,7 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="af7ffdf2-4ddc-4ed6-8222-60ed5acbc2ed" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/src/分治法/q34_在排序数组中查找元素的第一个和最后一个位置/Solution.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/动态规划/q64_最小路径和/Solution.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/README.md" beforeDir="false" afterPath="$PROJECT_DIR$/README.md" afterDir="false" />
</list>
@ -264,14 +264,7 @@
<workItem from="1585037684584" duration="753000" />
<workItem from="1585041029099" duration="2193000" />
<workItem from="1585219892120" duration="917000" />
<workItem from="1585223904505" duration="5402000" />
</task>
<task id="LOCAL-00007" summary="add q26/q43">
<created>1580496640692</created>
<option name="number" value="00007" />
<option name="presentableId" value="LOCAL-00007" />
<option name="project" value="LOCAL" />
<updated>1580496640692</updated>
<workItem from="1585223904505" duration="5628000" />
</task>
<task id="LOCAL-00008" summary="add q46">
<created>1580585083883</created>
@ -609,7 +602,14 @@
<option name="project" value="LOCAL" />
<updated>1585226292788</updated>
</task>
<option name="localTasksCounter" value="56" />
<task id="LOCAL-00056" summary="add q34">
<created>1585230484320</created>
<option name="number" value="00056" />
<option name="presentableId" value="LOCAL-00056" />
<option name="project" value="LOCAL" />
<updated>1585230484320</updated>
</task>
<option name="localTasksCounter" value="57" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
@ -662,7 +662,6 @@
</option>
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="add q42" />
<MESSAGE value="update md" />
<MESSAGE value="update q10/q746" />
<MESSAGE value="update q10" />
@ -687,7 +686,8 @@
<MESSAGE value="add q70/q104" />
<MESSAGE value="add q19" />
<MESSAGE value="add q32" />
<option name="LAST_COMMIT_MESSAGE" value="add q32" />
<MESSAGE value="add q34" />
<option name="LAST_COMMIT_MESSAGE" value="add q34" />
</component>
<component name="WindowStateProjectService">
<state x="320" y="115" key="#Inspections" timestamp="1581061018990">
@ -702,10 +702,10 @@
<screen x="0" y="0" width="1440" height="900" />
</state>
<state x="533" y="166" key="#com.intellij.ide.util.MemberChooser/0.0.1440.900@0.0.1440.900" timestamp="1578548165321" />
<state x="303" y="50" key="CommitChangelistDialog2" timestamp="1585226292610">
<state x="303" y="50" key="CommitChangelistDialog2" timestamp="1585230484170">
<screen x="0" y="0" width="1440" height="900" />
</state>
<state x="303" y="50" key="CommitChangelistDialog2/0.0.1440.900@0.0.1440.900" timestamp="1585226292610" />
<state x="303" y="50" key="CommitChangelistDialog2/0.0.1440.900@0.0.1440.900" timestamp="1585230484170" />
<state x="143" y="78" width="1152" height="720" key="DiffContextDialog" timestamp="1585027870766">
<screen x="0" y="0" width="1440" height="900" />
</state>
@ -760,10 +760,10 @@
<screen x="0" y="0" width="1440" height="900" />
</state>
<state x="221" y="63" key="SettingsEditor/0.0.1440.900@0.0.1440.900" timestamp="1585223890241" />
<state x="320" y="190" key="Vcs.Push.Dialog.v2" timestamp="1585226293961">
<state x="320" y="190" key="Vcs.Push.Dialog.v2" timestamp="1585230485339">
<screen x="0" y="0" width="1440" height="900" />
</state>
<state x="320" y="190" key="Vcs.Push.Dialog.v2/0.0.1440.900@0.0.1440.900" timestamp="1585226293961" />
<state x="320" y="190" key="Vcs.Push.Dialog.v2/0.0.1440.900@0.0.1440.900" timestamp="1585230485339" />
<state x="100" y="100" width="1240" height="700" key="com.intellij.history.integration.ui.views.DirectoryHistoryDialog" timestamp="1581744794182">
<screen x="0" y="23" width="1440" height="797" />
</state>

@ -85,6 +85,7 @@
* [q5_最长回文子串](/src/动态规划/q5_最长回文子串)
* [q53_最大子序和](/src/动态规划/q53_最大子序和)
* [q64_最小路径和](/src/动态规划/q64_最小路径和)
* [q70_爬楼梯](/src/动态规划/q70_爬楼梯)
* [q118_杨辉三角](/src/动态规划/q118_杨辉三角)
* [q300_最长上升子序列](/src/动态规划/q300_最长上升子序列)

@ -0,0 +1,26 @@
package .q64_;
/**
* dp(j)=grid(i,j)+min(dp(j),dp(j+1)) o(m*n)
*/
public class Solution {
public int minPathSum(int[][] grid) {
int[] dp = new int[grid[0].length];
for (int i = grid.length - 1; i >= 0; i--) {
for (int j = grid[0].length - 1; j >= 0; j--) {
if (i == grid.length - 1 && j != grid[0].length - 1) {
dp[j] = grid[i][j] + dp[j + 1];
} else if (j == grid[0].length - 1 && i != grid.length - 1) {
dp[j] = grid[i][j] + dp[j];
} else if (j != grid[0].length - 1 && i != grid.length - 1) {
dp[j] = grid[i][j] + Math.min(dp[j], dp[j + 1]);
} else {
dp[j] = grid[i][j];
}
}
}
return dp[0];
}
}
Loading…
Cancel
Save