pull/6/head
yuanguangxin 4 years ago
parent bb5208b0cc
commit 4dfbf67583

@ -2,10 +2,9 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="af7ffdf2-4ddc-4ed6-8222-60ed5acbc2ed" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/src/q46/Solution.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/q46/f2/Solution.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/q53/q1/Solution.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/q53/q2/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$/src/q236/Solution.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/q236/Solution.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -75,7 +74,7 @@
<recent name="$PROJECT_DIR$/src/q206/f1" />
</key>
</component>
<component name="RunManager" selected="Application.Solution (1)">
<component name="RunManager" selected="Application.Solution (5)">
<configuration name="Solution (1)" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="q46.f2.Solution" />
<module name="LeetCode" />
@ -128,12 +127,25 @@
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="Solution (5)" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="q53.q2.Solution" />
<module name="LeetCode" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="q53.q2.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="Solution" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="q46.f1.Solution" />
<option name="MAIN_CLASS_NAME" value="q53.q1.Solution" />
<module name="LeetCode" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="q46.f1.*" />
<option name="PATTERN" value="q53.q1.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
@ -169,11 +181,11 @@
</configuration>
<recent_temporary>
<list>
<item itemvalue="Application.Solution (5)" />
<item itemvalue="Application.Solution (5)" />
<item itemvalue="Application.Solution (1)" />
<item itemvalue="Application.Solution (2)" />
<item itemvalue="Application.Solution (5)" />
<item itemvalue="Application.Solution (4)" />
<item itemvalue="Application.Solution (3)" />
</list>
</recent_temporary>
</component>
@ -212,7 +224,8 @@
<workItem from="1579758668363" duration="319000" />
<workItem from="1579759214129" duration="10251000" />
<workItem from="1580044287086" duration="50376000" />
<workItem from="1580562331089" duration="8037000" />
<workItem from="1580562331089" duration="8289000" />
<workItem from="1580626297484" duration="10002000" />
</task>
<task id="LOCAL-00001" summary="add q5/q7/q172">
<created>1580045439607</created>
@ -263,7 +276,14 @@
<option name="project" value="LOCAL" />
<updated>1580496640692</updated>
</task>
<option name="localTasksCounter" value="8" />
<task id="LOCAL-00008" summary="add q46">
<created>1580585083883</created>
<option name="number" value="00008" />
<option name="presentableId" value="LOCAL-00008" />
<option name="project" value="LOCAL" />
<updated>1580585083883</updated>
</task>
<option name="localTasksCounter" value="9" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
@ -277,69 +297,70 @@
<MESSAGE value="add q14/q16/q20" />
<MESSAGE value="add q21" />
<MESSAGE value="add q26/q43" />
<option name="LAST_COMMIT_MESSAGE" value="add q26/q43" />
<MESSAGE value="add q46" />
<option name="LAST_COMMIT_MESSAGE" value="add q46" />
</component>
<component name="WindowStateProjectService">
<state x="533" y="166" key="#com.intellij.ide.util.MemberChooser" timestamp="1578548165321">
<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="1580496640466">
<state x="303" y="50" key="CommitChangelistDialog2" timestamp="1580585083630">
<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="1580496640466" />
<state x="144" y="78" key="DiffContextDialog" timestamp="1580395639517">
<state x="303" y="50" key="CommitChangelistDialog2/0.0.1440.900@0.0.1440.900" timestamp="1580585083630" />
<state x="144" y="78" key="DiffContextDialog" timestamp="1580585072145">
<screen x="0" y="0" width="1440" height="900" />
</state>
<state x="144" y="78" key="DiffContextDialog/0.0.1440.900@0.0.1440.900" timestamp="1580395639517" />
<state width="1398" height="261" key="GridCell.Tab.0.bottom" timestamp="1580584338381">
<state x="144" y="78" key="DiffContextDialog/0.0.1440.900@0.0.1440.900" timestamp="1580585072145" />
<state width="1398" height="204" key="GridCell.Tab.0.bottom" timestamp="1580714110161">
<screen x="0" y="0" width="1440" height="900" />
</state>
<state width="1398" height="261" key="GridCell.Tab.0.bottom/0.0.1440.900@0.0.1440.900" timestamp="1580584338381" />
<state width="1398" height="204" key="GridCell.Tab.0.bottom/0.23.1440.797@0.23.1440.797" timestamp="1580579638273" />
<state width="1398" height="261" key="GridCell.Tab.0.center" timestamp="1580584338379">
<state width="1398" height="204" key="GridCell.Tab.0.bottom/0.0.1440.900@0.0.1440.900" timestamp="1580714110161" />
<state width="1398" height="204" key="GridCell.Tab.0.bottom/0.23.1440.797@0.23.1440.797" timestamp="1580706887662" />
<state width="1398" height="204" key="GridCell.Tab.0.center" timestamp="1580714110159">
<screen x="0" y="0" width="1440" height="900" />
</state>
<state width="1398" height="261" key="GridCell.Tab.0.center/0.0.1440.900@0.0.1440.900" timestamp="1580584338379" />
<state width="1398" height="204" key="GridCell.Tab.0.center/0.23.1440.797@0.23.1440.797" timestamp="1580579638270" />
<state width="1398" height="261" key="GridCell.Tab.0.left" timestamp="1580584338378">
<state width="1398" height="204" key="GridCell.Tab.0.center/0.0.1440.900@0.0.1440.900" timestamp="1580714110159" />
<state width="1398" height="204" key="GridCell.Tab.0.center/0.23.1440.797@0.23.1440.797" timestamp="1580706887660" />
<state width="1398" height="204" key="GridCell.Tab.0.left" timestamp="1580714110158">
<screen x="0" y="0" width="1440" height="900" />
</state>
<state width="1398" height="261" key="GridCell.Tab.0.left/0.0.1440.900@0.0.1440.900" timestamp="1580584338378" />
<state width="1398" height="204" key="GridCell.Tab.0.left/0.23.1440.797@0.23.1440.797" timestamp="1580579638269" />
<state width="1398" height="261" key="GridCell.Tab.0.right" timestamp="1580584338380">
<state width="1398" height="204" key="GridCell.Tab.0.left/0.0.1440.900@0.0.1440.900" timestamp="1580714110158" />
<state width="1398" height="204" key="GridCell.Tab.0.left/0.23.1440.797@0.23.1440.797" timestamp="1580706887659" />
<state width="1398" height="204" key="GridCell.Tab.0.right" timestamp="1580714110160">
<screen x="0" y="0" width="1440" height="900" />
</state>
<state width="1398" height="261" key="GridCell.Tab.0.right/0.0.1440.900@0.0.1440.900" timestamp="1580584338380" />
<state width="1398" height="204" key="GridCell.Tab.0.right/0.23.1440.797@0.23.1440.797" timestamp="1580579638271" />
<state width="1398" height="261" key="GridCell.Tab.1.bottom" timestamp="1580584338384">
<state width="1398" height="204" key="GridCell.Tab.0.right/0.0.1440.900@0.0.1440.900" timestamp="1580714110160" />
<state width="1398" height="204" key="GridCell.Tab.0.right/0.23.1440.797@0.23.1440.797" timestamp="1580706887661" />
<state width="1398" height="261" key="GridCell.Tab.1.bottom" timestamp="1580626092580">
<screen x="0" y="0" width="1440" height="900" />
</state>
<state width="1398" height="261" key="GridCell.Tab.1.bottom/0.0.1440.900@0.0.1440.900" timestamp="1580584338384" />
<state width="1398" height="261" key="GridCell.Tab.1.bottom/0.0.1440.900@0.0.1440.900" timestamp="1580626092580" />
<state width="1398" height="304" key="GridCell.Tab.1.bottom/0.23.1440.797@0.23.1440.797" timestamp="1580408030266" />
<state width="1398" height="261" key="GridCell.Tab.1.center" timestamp="1580584338383">
<state width="1398" height="261" key="GridCell.Tab.1.center" timestamp="1580626092579">
<screen x="0" y="0" width="1440" height="900" />
</state>
<state width="1398" height="261" key="GridCell.Tab.1.center/0.0.1440.900@0.0.1440.900" timestamp="1580584338383" />
<state width="1398" height="261" key="GridCell.Tab.1.center/0.0.1440.900@0.0.1440.900" timestamp="1580626092579" />
<state width="1398" height="304" key="GridCell.Tab.1.center/0.23.1440.797@0.23.1440.797" timestamp="1580408030265" />
<state width="1398" height="261" key="GridCell.Tab.1.left" timestamp="1580584338382">
<state width="1398" height="261" key="GridCell.Tab.1.left" timestamp="1580626092578">
<screen x="0" y="0" width="1440" height="900" />
</state>
<state width="1398" height="261" key="GridCell.Tab.1.left/0.0.1440.900@0.0.1440.900" timestamp="1580584338382" />
<state width="1398" height="261" key="GridCell.Tab.1.left/0.0.1440.900@0.0.1440.900" timestamp="1580626092578" />
<state width="1398" height="304" key="GridCell.Tab.1.left/0.23.1440.797@0.23.1440.797" timestamp="1580408030262" />
<state width="1398" height="261" key="GridCell.Tab.1.right" timestamp="1580584338384">
<state width="1398" height="261" key="GridCell.Tab.1.right" timestamp="1580626092579">
<screen x="0" y="0" width="1440" height="900" />
</state>
<state width="1398" height="261" key="GridCell.Tab.1.right/0.0.1440.900@0.0.1440.900" timestamp="1580584338384" />
<state width="1398" height="261" key="GridCell.Tab.1.right/0.0.1440.900@0.0.1440.900" timestamp="1580626092579" />
<state width="1398" height="304" key="GridCell.Tab.1.right/0.23.1440.797@0.23.1440.797" timestamp="1580408030266" />
<state x="221" y="88" key="SettingsEditor" timestamp="1580562273160">
<screen x="0" y="0" width="1440" height="900" />
</state>
<state x="221" y="88" key="SettingsEditor/0.0.1440.900@0.0.1440.900" timestamp="1580562273160" />
<state x="320" y="190" key="Vcs.Push.Dialog.v2" timestamp="1580496641807">
<state x="320" y="190" key="Vcs.Push.Dialog.v2" timestamp="1580585085542">
<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="1580496641807" />
<state x="320" y="190" key="Vcs.Push.Dialog.v2/0.0.1440.900@0.0.1440.900" timestamp="1580585085542" />
<state x="378" y="207" width="683" height="486" key="find.popup" timestamp="1578496174047">
<screen x="0" y="0" width="1440" height="900" />
</state>

@ -0,0 +1,31 @@
package q53.q1;
/**
* o(n)
*/
public class Solution {
public int maxSubArray(int[] nums) {
if (nums.length == 1) {
return nums[0];
}
int sum = nums[0];
int temp = sum;
for (int i = 1; i < nums.length; i++) {
temp = temp + nums[i];
if (temp >= sum) {
sum = temp;
} else if (temp < 0) {
temp = 0;
}
if (nums[i] > sum) {
temp = nums[i];
sum = nums[i];
}
}
return sum;
}
public static void main(String[] args) {
System.out.println(new Solution().maxSubArray(new int[]{-1, 1, 2, 1}));
}
}

@ -0,0 +1,24 @@
package q53.q2;
/**
* dp[i]nums[i] o(n)
*/
public class Solution {
public int maxSubArray(int[] nums) {
int[] dp = new int[nums.length];
dp[0] = nums[0];
int rs = dp[0];
for (int i = 1; i < nums.length; i++) {
int temp = dp[i - 1] + nums[i];
dp[i] = Math.max(nums[i],temp);
rs = Math.max(rs, dp[i]);
}
return rs;
}
public static void main(String[] args) {
System.out.println(new Solution().maxSubArray(new int[]{-2}));
}
}
Loading…
Cancel
Save