add q3/q8/q11

pull/6/head
yuanguangxin 5 years ago
parent 5c7a63cc15
commit c71f90dfb6

@ -1,8 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="af7ffdf2-4ddc-4ed6-8222-60ed5acbc2ed" name="Default Changelist" comment="add q5/q7/q172">
<change afterPath="$PROJECT_DIR$/src/q9/Solution.java" afterDir="false" />
<list default="true" id="af7ffdf2-4ddc-4ed6-8222-60ed5acbc2ed" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/src/q11/Solution.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/q3/Solution.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/q8/Solution.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
@ -54,6 +56,7 @@
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="SHARE_PROJECT_CONFIGURATION_FILES" value="true" />
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="add_unversioned_files" value="true" />
<property name="aspect.path.notification.shown" value="true" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/src/etc/q1" />
<property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
@ -70,13 +73,13 @@
<recent name="$PROJECT_DIR$/src/q206/f1" />
</key>
</component>
<component name="RunManager" selected="Application.Solution (2)">
<configuration name="Solution (2)" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="q7.f2.Solution" />
<component name="RunManager" selected="Application.Solution (3)">
<configuration name="Solution (1)" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="q172.f2.Solution" />
<module name="LeetCode" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="q7.f2.*" />
<option name="PATTERN" value="q172.f2.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
@ -84,12 +87,12 @@
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="Solution (3)" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="q7.f1.Solution" />
<configuration name="Solution (2)" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="q7.f2.Solution" />
<module name="LeetCode" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="q7.f1.*" />
<option name="PATTERN" value="q7.f2.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
@ -97,12 +100,12 @@
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="Solution (4)" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="q9.Solution" />
<configuration name="Solution (3)" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="q3.Solution" />
<module name="LeetCode" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="q9.*" />
<option name="PATTERN" value="q3.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
@ -110,12 +113,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="q5.f2.Solution" />
<configuration name="Solution (5)" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="q11.Solution" />
<module name="LeetCode" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="q5.f2.*" />
<option name="PATTERN" value="q11.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
@ -124,11 +127,11 @@
</method>
</configuration>
<configuration name="Solution" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="q7.f1.Solution" />
<option name="MAIN_CLASS_NAME" value="q8.Solution" />
<module name="LeetCode" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="q7.f1.*" />
<option name="PATTERN" value="q8.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
@ -137,11 +140,11 @@
</method>
</configuration>
<configuration name="Solution" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="q1.f2.Solution" />
<option name="MAIN_CLASS_NAME" value="q7.f1.Solution" />
<module name="LeetCode" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="q1.f1.*" />
<option name="PATTERN" value="q7.f1.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
@ -149,12 +152,12 @@
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="Threads" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="etc.ali.q3.Threads" />
<configuration name="Solution" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="q1.f2.Solution" />
<module name="LeetCode" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="etc.ali.q3.*" />
<option name="PATTERN" value="q1.f1.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
@ -164,11 +167,11 @@
</configuration>
<recent_temporary>
<list>
<item itemvalue="Application.Solution (2)" />
<item itemvalue="Application.Solution (4)" />
<item itemvalue="Application.Solution (3)" />
<item itemvalue="Application.Solution (2)" />
<item itemvalue="Application.Solution (5)" />
<item itemvalue="Application.Solution" />
<item itemvalue="Application.Solution (1)" />
<item itemvalue="Application.Solution (2)" />
</list>
</recent_temporary>
</component>
@ -206,7 +209,7 @@
<workItem from="1579695121386" duration="2796000" />
<workItem from="1579758668363" duration="319000" />
<workItem from="1579759214129" duration="10251000" />
<workItem from="1580044287086" duration="7777000" />
<workItem from="1580044287086" duration="19942000" />
</task>
<task id="LOCAL-00001" summary="add q5/q7/q172">
<created>1580045439607</created>
@ -215,7 +218,14 @@
<option name="project" value="LOCAL" />
<updated>1580045439608</updated>
</task>
<option name="localTasksCounter" value="2" />
<task id="LOCAL-00002" summary="add q9">
<created>1580057171456</created>
<option name="number" value="00002" />
<option name="presentableId" value="LOCAL-00002" />
<option name="project" value="LOCAL" />
<updated>1580057171456</updated>
</task>
<option name="localTasksCounter" value="3" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
@ -223,65 +233,66 @@
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="add q5/q7/q172" />
<option name="LAST_COMMIT_MESSAGE" value="add q5/q7/q172" />
<MESSAGE value="add q9" />
<option name="LAST_COMMIT_MESSAGE" value="add q9" />
</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="1580045607834">
<state x="303" y="50" key="CommitChangelistDialog2" timestamp="1580235163178">
<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="1580045607834" />
<state width="1398" height="193" key="GridCell.Tab.0.bottom" timestamp="1580057111711">
<state x="303" y="50" key="CommitChangelistDialog2/0.0.1440.900@0.0.1440.900" timestamp="1580235163178" />
<state width="1398" height="166" key="GridCell.Tab.0.bottom" timestamp="1580234677984">
<screen x="0" y="0" width="1440" height="900" />
</state>
<state width="1398" height="193" key="GridCell.Tab.0.bottom/0.0.1440.900@0.0.1440.900" timestamp="1580057111711" />
<state width="1398" height="166" key="GridCell.Tab.0.bottom/0.0.1440.900@0.0.1440.900" timestamp="1580234677984" />
<state width="1398" height="193" key="GridCell.Tab.0.bottom/0.23.1440.797@0.23.1440.797" timestamp="1579796075437" />
<state width="1398" height="193" key="GridCell.Tab.0.center" timestamp="1580057111710">
<state width="1398" height="166" key="GridCell.Tab.0.center" timestamp="1580234677983">
<screen x="0" y="0" width="1440" height="900" />
</state>
<state width="1398" height="193" key="GridCell.Tab.0.center/0.0.1440.900@0.0.1440.900" timestamp="1580057111710" />
<state width="1398" height="166" key="GridCell.Tab.0.center/0.0.1440.900@0.0.1440.900" timestamp="1580234677983" />
<state width="1398" height="193" key="GridCell.Tab.0.center/0.23.1440.797@0.23.1440.797" timestamp="1579796075436" />
<state width="1398" height="193" key="GridCell.Tab.0.left" timestamp="1580057111709">
<state width="1398" height="166" key="GridCell.Tab.0.left" timestamp="1580234677982">
<screen x="0" y="0" width="1440" height="900" />
</state>
<state width="1398" height="193" key="GridCell.Tab.0.left/0.0.1440.900@0.0.1440.900" timestamp="1580057111709" />
<state width="1398" height="166" key="GridCell.Tab.0.left/0.0.1440.900@0.0.1440.900" timestamp="1580234677982" />
<state width="1398" height="193" key="GridCell.Tab.0.left/0.23.1440.797@0.23.1440.797" timestamp="1579796075435" />
<state width="1398" height="193" key="GridCell.Tab.0.right" timestamp="1580057111710">
<state width="1398" height="166" key="GridCell.Tab.0.right" timestamp="1580234677983">
<screen x="0" y="0" width="1440" height="900" />
</state>
<state width="1398" height="193" key="GridCell.Tab.0.right/0.0.1440.900@0.0.1440.900" timestamp="1580057111710" />
<state width="1398" height="166" key="GridCell.Tab.0.right/0.0.1440.900@0.0.1440.900" timestamp="1580234677983" />
<state width="1398" height="193" key="GridCell.Tab.0.right/0.23.1440.797@0.23.1440.797" timestamp="1579796075437" />
<state width="1398" height="134" key="GridCell.Tab.1.bottom" timestamp="1580056329388">
<state width="1398" height="304" key="GridCell.Tab.1.bottom" timestamp="1580234535534">
<screen x="0" y="0" width="1440" height="900" />
</state>
<state width="1398" height="134" key="GridCell.Tab.1.bottom/0.0.1440.900@0.0.1440.900" timestamp="1580056329388" />
<state width="1398" height="304" key="GridCell.Tab.1.bottom/0.0.1440.900@0.0.1440.900" timestamp="1580234535534" />
<state width="1398" height="303" key="GridCell.Tab.1.bottom/0.23.1440.797@0.23.1440.797" timestamp="1579765319366" />
<state width="1398" height="134" key="GridCell.Tab.1.center" timestamp="1580056329386">
<state width="1398" height="304" key="GridCell.Tab.1.center" timestamp="1580234535532">
<screen x="0" y="0" width="1440" height="900" />
</state>
<state width="1398" height="134" key="GridCell.Tab.1.center/0.0.1440.900@0.0.1440.900" timestamp="1580056329386" />
<state width="1398" height="304" key="GridCell.Tab.1.center/0.0.1440.900@0.0.1440.900" timestamp="1580234535532" />
<state width="1398" height="303" key="GridCell.Tab.1.center/0.23.1440.797@0.23.1440.797" timestamp="1579765319364" />
<state width="1398" height="134" key="GridCell.Tab.1.left" timestamp="1580056329385">
<state width="1398" height="304" key="GridCell.Tab.1.left" timestamp="1580234535531">
<screen x="0" y="0" width="1440" height="900" />
</state>
<state width="1398" height="134" key="GridCell.Tab.1.left/0.0.1440.900@0.0.1440.900" timestamp="1580056329385" />
<state width="1398" height="304" key="GridCell.Tab.1.left/0.0.1440.900@0.0.1440.900" timestamp="1580234535531" />
<state width="1398" height="303" key="GridCell.Tab.1.left/0.23.1440.797@0.23.1440.797" timestamp="1579765319363" />
<state width="1398" height="134" key="GridCell.Tab.1.right" timestamp="1580056329387">
<state width="1398" height="304" key="GridCell.Tab.1.right" timestamp="1580234535532">
<screen x="0" y="0" width="1440" height="900" />
</state>
<state width="1398" height="134" key="GridCell.Tab.1.right/0.0.1440.900@0.0.1440.900" timestamp="1580056329387" />
<state width="1398" height="304" key="GridCell.Tab.1.right/0.0.1440.900@0.0.1440.900" timestamp="1580234535532" />
<state width="1398" height="303" key="GridCell.Tab.1.right/0.23.1440.797@0.23.1440.797" timestamp="1579765319365" />
<state x="221" y="88" key="SettingsEditor" timestamp="1578704600210">
<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="1578704600210" />
<state x="320" y="190" key="Vcs.Push.Dialog.v2" timestamp="1580045441684">
<state x="320" y="190" key="Vcs.Push.Dialog.v2" timestamp="1580057172706">
<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="1580045441684" />
<state x="320" y="190" key="Vcs.Push.Dialog.v2/0.0.1440.900@0.0.1440.900" timestamp="1580057172706" />
<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,32 @@
package q11;
/**
* o(n)
*/
public class Solution {
public int maxArea(int[] height) {
if (height.length < 2) {
return 0;
}
int left = 0;
int right = height.length - 1;
int result = 0;
while (right > left) {
int c = (Math.min(height[right], height[left])) * (right - left);
if (c >= result) {
result = c;
}
if (height[left] < height[right]) {
left++;
} else {
right--;
}
}
return result;
}
public static void main(String[] args) {
int[] a = new int[]{1, 8, 6, 2, 5, 4, 8, 3, 7};
System.out.println(new Solution().maxArea(a));
}
}

@ -0,0 +1,27 @@
package q3;
import java.util.HashMap;
/**
* Hash+ o(n)
*/
public class Solution {
public int lengthOfLongestSubstring(String s) {
int left = 0;
int right = 0;
int len = 0;
HashMap<Character, Integer> map = new HashMap<>();
while (right < s.length()) {
Integer index = map.get(s.charAt(right));
map.put(s.charAt(right), right);
if (index != null && index >= left) {
left = index + 1;
}
if (right - left + 1 > len) {
len = right - left + 1;
}
right++;
}
return len;
}
}

@ -0,0 +1,40 @@
package q8;
/**
* o(n)
*/
public class Solution {
public int myAtoi(String str) {
str = str.trim();
if (str.length() < 1) {
return 0;
}
boolean negative = false;
if (str.charAt(0) == '-') {
negative = true;
str = str.substring(1);
} else if (str.charAt(0) == '+') {
str = str.substring(1);
}
int rs = 0;
for (int i = 0; i < str.length(); i++) {
char t = str.charAt(i);
if (Character.isDigit(t)) {
int temp = rs * 10 - '0' + t;
if ((temp - t + '0') / 10 != rs || temp < 0) {
return negative ? Integer.MIN_VALUE : Integer.MAX_VALUE;
}
rs = temp;
} else {
break;
}
}
return negative ? -rs : rs;
}
public static void main(String[] args) {
System.out.println(new Solution().myAtoi("2147483648"));
}
}
Loading…
Cancel
Save