pull/6/head
yuanguangxin 5 years ago
parent 962f808cf9
commit f306cb3332

@ -2,8 +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/链表操作/q19_删除链表的倒数第N个节点/ListNode.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/链表操作/q19_删除链表的倒数第N个节点/Solution.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/栈相关/q32_最长有效括号/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>
@ -64,7 +63,7 @@
<property name="project.structure.last.edited" value="Modules" />
<property name="project.structure.proportion" value="0.15" />
<property name="project.structure.side.proportion" value="0.2" />
<property name="settings.editor.selected.configurable" value="MavenSettings" />
<property name="settings.editor.selected.configurable" value="preferences.pluginManager" />
</component>
<component name="RecentsManager">
<key name="CopyClassDialog.RECENTS_KEY">
@ -81,20 +80,7 @@
<recent name="$PROJECT_DIR$/src/q206/f1" />
</key>
</component>
<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="hash相关.q1_两数之和.f1.Solution" />
<module name="LeetCode" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="hash相关.q1_两数之和.f1.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<component name="RunManager" selected="Application.Solution (6)">
<configuration name="Solution (2)" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="双指针遍历.q121_买卖股票的最佳时机.Solution" />
<module name="LeetCode" />
@ -147,12 +133,12 @@
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="Solution" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="q10_正则表达式匹配.Solution" />
<configuration name="Solution (6)" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="栈相关.q32_最长有效括号.Solution" />
<module name="LeetCode" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="q10_正则表达式匹配.*" />
<option name="PATTERN" value="栈相关.q32_最长有效括号.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
@ -227,11 +213,11 @@
</configuration>
<recent_temporary>
<list>
<item itemvalue="Application.Solution (6)" />
<item itemvalue="Application.Solution (5)" />
<item itemvalue="Application.Solution (4)" />
<item itemvalue="Application.Solution (3)" />
<item itemvalue="Application.Solution (2)" />
<item itemvalue="Application.Solution (1)" />
</list>
</recent_temporary>
</component>
@ -290,14 +276,8 @@
<workItem from="1584977075044" duration="499000" />
<workItem from="1585037684584" duration="753000" />
<workItem from="1585041029099" duration="2193000" />
<workItem from="1585219892120" duration="222000" />
</task>
<task id="LOCAL-00005" summary="add q14/q16/q20">
<created>1580395653122</created>
<option name="number" value="00005" />
<option name="presentableId" value="LOCAL-00005" />
<option name="project" value="LOCAL" />
<updated>1580395653122</updated>
<workItem from="1585219892120" duration="917000" />
<workItem from="1585223904505" duration="2190000" />
</task>
<task id="LOCAL-00006" summary="add q21">
<created>1580409713059</created>
@ -635,7 +615,14 @@
<option name="project" value="LOCAL" />
<updated>1585108622120</updated>
</task>
<option name="localTasksCounter" value="54" />
<task id="LOCAL-00054" summary="add q19">
<created>1585220219370</created>
<option name="number" value="00054" />
<option name="presentableId" value="LOCAL-00054" />
<option name="project" value="LOCAL" />
<updated>1585220219370</updated>
</task>
<option name="localTasksCounter" value="55" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
@ -688,7 +675,6 @@
</option>
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="add q110/q450/q701" />
<MESSAGE value="add q1277" />
<MESSAGE value="add q42" />
<MESSAGE value="update md" />
@ -713,7 +699,8 @@
<MESSAGE value="update Rocket.md" />
<MESSAGE value="add q945" />
<MESSAGE value="add q70/q104" />
<option name="LAST_COMMIT_MESSAGE" value="add q70/q104" />
<MESSAGE value="add q19" />
<option name="LAST_COMMIT_MESSAGE" value="add q19" />
</component>
<component name="WindowStateProjectService">
<state x="320" y="115" key="#Inspections" timestamp="1581061018990">
@ -728,35 +715,35 @@
<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="1585108621969">
<state x="303" y="50" key="CommitChangelistDialog2" timestamp="1585220219177">
<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="1585108621969" />
<state x="303" y="50" key="CommitChangelistDialog2/0.0.1440.900@0.0.1440.900" timestamp="1585220219177" />
<state x="143" y="78" width="1152" height="720" key="DiffContextDialog" timestamp="1585027870766">
<screen x="0" y="0" width="1440" height="900" />
</state>
<state x="143" y="78" width="1152" height="720" key="DiffContextDialog/0.0.1440.900@0.0.1440.900" timestamp="1585027870766" />
<state x="144" y="78" width="1152" height="720" key="DiffContextDialog/0.23.1440.793@0.23.1440.793" timestamp="1582714686712" />
<state x="144" y="78" width="1152" height="720" key="DiffContextDialog/0.23.1440.797@0.23.1440.797" timestamp="1581927787180" />
<state width="1398" height="236" key="GridCell.Tab.0.bottom" timestamp="1583494105225">
<state width="1398" height="245" key="GridCell.Tab.0.bottom" timestamp="1585224543864">
<screen x="0" y="0" width="1440" height="900" />
</state>
<state width="1398" height="236" key="GridCell.Tab.0.bottom/0.0.1440.900@0.0.1440.900" timestamp="1583494105225" />
<state width="1398" height="245" key="GridCell.Tab.0.bottom/0.0.1440.900@0.0.1440.900" timestamp="1585224543864" />
<state width="1398" height="177" key="GridCell.Tab.0.bottom/0.23.1440.797@0.23.1440.797" timestamp="1581533895880" />
<state width="1398" height="236" key="GridCell.Tab.0.center" timestamp="1583494105224">
<state width="1398" height="245" key="GridCell.Tab.0.center" timestamp="1585224543863">
<screen x="0" y="0" width="1440" height="900" />
</state>
<state width="1398" height="236" key="GridCell.Tab.0.center/0.0.1440.900@0.0.1440.900" timestamp="1583494105224" />
<state width="1398" height="245" key="GridCell.Tab.0.center/0.0.1440.900@0.0.1440.900" timestamp="1585224543863" />
<state width="1398" height="177" key="GridCell.Tab.0.center/0.23.1440.797@0.23.1440.797" timestamp="1581533895878" />
<state width="1398" height="236" key="GridCell.Tab.0.left" timestamp="1583494105223">
<state width="1398" height="245" key="GridCell.Tab.0.left" timestamp="1585224543862">
<screen x="0" y="0" width="1440" height="900" />
</state>
<state width="1398" height="236" key="GridCell.Tab.0.left/0.0.1440.900@0.0.1440.900" timestamp="1583494105223" />
<state width="1398" height="245" key="GridCell.Tab.0.left/0.0.1440.900@0.0.1440.900" timestamp="1585224543862" />
<state width="1398" height="177" key="GridCell.Tab.0.left/0.23.1440.797@0.23.1440.797" timestamp="1581533895878" />
<state width="1398" height="236" key="GridCell.Tab.0.right" timestamp="1583494105225">
<state width="1398" height="245" key="GridCell.Tab.0.right" timestamp="1585224543863">
<screen x="0" y="0" width="1440" height="900" />
</state>
<state width="1398" height="236" key="GridCell.Tab.0.right/0.0.1440.900@0.0.1440.900" timestamp="1583494105225" />
<state width="1398" height="245" key="GridCell.Tab.0.right/0.0.1440.900@0.0.1440.900" timestamp="1585224543863" />
<state width="1398" height="177" key="GridCell.Tab.0.right/0.23.1440.797@0.23.1440.797" timestamp="1581533895879" />
<state width="1398" height="204" key="GridCell.Tab.1.bottom" timestamp="1581745235895">
<screen x="0" y="0" width="1440" height="900" />
@ -782,14 +769,14 @@
<screen x="0" y="0" width="1440" height="900" />
</state>
<state x="431" y="173" key="MultipleFileMergeDialog/0.0.1440.900@0.0.1440.900" timestamp="1582971939233" />
<state x="221" y="63" key="SettingsEditor" timestamp="1583244442349">
<state x="221" y="63" key="SettingsEditor" timestamp="1585223890241">
<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="1583244442349" />
<state x="320" y="190" key="Vcs.Push.Dialog.v2" timestamp="1585108623353">
<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="1585220220623">
<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="1585108623353" />
<state x="320" y="190" key="Vcs.Push.Dialog.v2/0.0.1440.900@0.0.1440.900" timestamp="1585220220623" />
<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>

@ -58,6 +58,7 @@
### 栈相关
* [q20_有效的括号](/src/栈相关/q20_有效的括号)
* [q32_最长有效括号](/src/栈相关/q32_最长有效括号)
* [q224_基本计算器](/src/栈相关/q224_基本计算器)
* [q316_去除重复字母](/src/栈相关/q316_去除重复字母)

@ -0,0 +1,38 @@
package .q32_;
import java.util.Stack;
/**
* o(n)
*/
public class Solution {
public int longestValidParentheses(String s) {
if (s == null || s.length() < 2) {
return 0;
}
int maxLen = 0;
Stack<Integer> stack = new Stack<>();
stack.push(-1);
for (int i = 0; i < s.length(); i++) {
char temp = s.charAt(i);
if (temp == '(') {
stack.push(i);
} else {
stack.pop();
if (stack.empty()) {
stack.push(i);
} else {
maxLen = Math.max(maxLen, i - stack.peek());
}
}
}
return maxLen;
}
public static void main(String[] args) {
System.out.println(new Solution().longestValidParentheses(")()())"));
}
}
Loading…
Cancel
Save