add q26/q43

pull/6/head
yuanguangxin 4 years ago
parent e6c44542f4
commit 9954ef31e8

@ -2,10 +2,8 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="af7ffdf2-4ddc-4ed6-8222-60ed5acbc2ed" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/src/q21/f1/ListNode.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/q21/f1/Solution.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/q21/f2/ListNode.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/q21/f2/Solution.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/q26/Solution.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/q43/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" />
@ -76,7 +74,7 @@
<recent name="$PROJECT_DIR$/src/q206/f1" />
</key>
</component>
<component name="RunManager" selected="Application.Solution (3)">
<component name="RunManager" selected="Application.Solution (4)">
<configuration name="Solution (1)" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="q14.Solution" />
<module name="LeetCode" />
@ -116,12 +114,12 @@
<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="q11.Solution" />
<configuration name="Solution (4)" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="q26.Solution" />
<module name="LeetCode" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="q11.*" />
<option name="PATTERN" value="q26.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
@ -170,11 +168,11 @@
</configuration>
<recent_temporary>
<list>
<item itemvalue="Application.Solution (4)" />
<item itemvalue="Application.Solution (3)" />
<item itemvalue="Application.Solution" />
<item itemvalue="Application.Solution (2)" />
<item itemvalue="Application.Solution (1)" />
<item itemvalue="Application.Solution (2)" />
</list>
</recent_temporary>
</component>
@ -212,7 +210,7 @@
<workItem from="1579695121386" duration="2796000" />
<workItem from="1579758668363" duration="319000" />
<workItem from="1579759214129" duration="10251000" />
<workItem from="1580044287086" duration="45860000" />
<workItem from="1580044287086" duration="48799000" />
</task>
<task id="LOCAL-00001" summary="add q5/q7/q172">
<created>1580045439607</created>
@ -249,7 +247,14 @@
<option name="project" value="LOCAL" />
<updated>1580395653122</updated>
</task>
<option name="localTasksCounter" value="6" />
<task id="LOCAL-00006" summary="add q21">
<created>1580409713059</created>
<option name="number" value="00006" />
<option name="presentableId" value="LOCAL-00006" />
<option name="project" value="LOCAL" />
<updated>1580409713059</updated>
</task>
<option name="localTasksCounter" value="7" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
@ -261,40 +266,41 @@
<MESSAGE value="add q3/q8/q11" />
<MESSAGE value="add q6" />
<MESSAGE value="add q14/q16/q20" />
<option name="LAST_COMMIT_MESSAGE" value="add q14/q16/q20" />
<MESSAGE value="add q21" />
<option name="LAST_COMMIT_MESSAGE" value="add q21" />
</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="1580395652919">
<state x="303" y="50" key="CommitChangelistDialog2" timestamp="1580409712777">
<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="1580395652919" />
<state x="303" y="50" key="CommitChangelistDialog2/0.0.1440.900@0.0.1440.900" timestamp="1580409712777" />
<state x="144" y="78" key="DiffContextDialog" timestamp="1580395639517">
<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="176" key="GridCell.Tab.0.bottom" timestamp="1580409258841">
<state width="1398" height="176" key="GridCell.Tab.0.bottom" timestamp="1580483674728">
<screen x="0" y="0" width="1440" height="900" />
</state>
<state width="1398" height="176" key="GridCell.Tab.0.bottom/0.0.1440.900@0.0.1440.900" timestamp="1580409258841" />
<state width="1398" height="176" key="GridCell.Tab.0.bottom/0.0.1440.900@0.0.1440.900" timestamp="1580483674728" />
<state width="1398" height="304" key="GridCell.Tab.0.bottom/0.23.1440.797@0.23.1440.797" timestamp="1580408030261" />
<state width="1398" height="176" key="GridCell.Tab.0.center" timestamp="1580409258839">
<state width="1398" height="176" key="GridCell.Tab.0.center" timestamp="1580483674725">
<screen x="0" y="0" width="1440" height="900" />
</state>
<state width="1398" height="176" key="GridCell.Tab.0.center/0.0.1440.900@0.0.1440.900" timestamp="1580409258839" />
<state width="1398" height="176" key="GridCell.Tab.0.center/0.0.1440.900@0.0.1440.900" timestamp="1580483674725" />
<state width="1398" height="304" key="GridCell.Tab.0.center/0.23.1440.797@0.23.1440.797" timestamp="1580408030259" />
<state width="1398" height="176" key="GridCell.Tab.0.left" timestamp="1580409258839">
<state width="1398" height="176" key="GridCell.Tab.0.left" timestamp="1580483674724">
<screen x="0" y="0" width="1440" height="900" />
</state>
<state width="1398" height="176" key="GridCell.Tab.0.left/0.0.1440.900@0.0.1440.900" timestamp="1580409258839" />
<state width="1398" height="176" key="GridCell.Tab.0.left/0.0.1440.900@0.0.1440.900" timestamp="1580483674724" />
<state width="1398" height="304" key="GridCell.Tab.0.left/0.23.1440.797@0.23.1440.797" timestamp="1580408030258" />
<state width="1398" height="176" key="GridCell.Tab.0.right" timestamp="1580409258840">
<state width="1398" height="176" key="GridCell.Tab.0.right" timestamp="1580483674727">
<screen x="0" y="0" width="1440" height="900" />
</state>
<state width="1398" height="176" key="GridCell.Tab.0.right/0.0.1440.900@0.0.1440.900" timestamp="1580409258840" />
<state width="1398" height="176" key="GridCell.Tab.0.right/0.0.1440.900@0.0.1440.900" timestamp="1580483674727" />
<state width="1398" height="304" key="GridCell.Tab.0.right/0.23.1440.797@0.23.1440.797" timestamp="1580408030260" />
<state width="1398" height="304" key="GridCell.Tab.1.bottom" timestamp="1580408030266">
<screen x="0" y="23" width="1440" height="797" />
@ -320,10 +326,10 @@
<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="1580395654745">
<state x="320" y="190" key="Vcs.Push.Dialog.v2" timestamp="1580409714367">
<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="1580395654745" />
<state x="320" y="190" key="Vcs.Push.Dialog.v2/0.0.1440.900@0.0.1440.900" timestamp="1580409714367" />
<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,24 @@
package q26;
/**
* o(n)
*/
public class Solution {
public int removeDuplicates(int[] nums) {
if (nums.length < 2) {
return nums.length;
}
int c = 0;
for (int i = 1; i < nums.length; i++) {
if (nums[i] != nums[c]) {
c++;
nums[c] = nums[i];
}
}
return c + 1;
}
public static void main(String[] args) {
new Solution().removeDuplicates(new int[]{1, 1, 2});
}
}

@ -0,0 +1,47 @@
package q43;
/**
* o(n)
*/
class Solution {
public String multiply(String num1, String num2) {
if (num1.equals("0") || num2.equals("0")) {
return "0";
}
String res = "0";
for (int i = num2.length() - 1; i >= 0; i--) {
int carry = 0;
StringBuilder temp = new StringBuilder();
for (int j = 0; j < num2.length() - 1 - i; j++) {
temp.append(0);
}
int n2 = num2.charAt(i) - '0';
for (int j = num1.length() - 1; j >= 0 || carry != 0; j--) {
int n1 = j < 0 ? 0 : num1.charAt(j) - '0';
int product = (n1 * n2 + carry) % 10;
temp.append(product);
carry = (n1 * n2 + carry) / 10;
}
res = addStrings(res, temp.reverse().toString());
}
return res;
}
public String addStrings(String num1, String num2) {
StringBuilder builder = new StringBuilder();
int carry = 0;
for (int i = num1.length() - 1, j = num2.length() - 1;
i >= 0 || j >= 0 || carry != 0;
i--, j--) {
int x = i < 0 ? 0 : num1.charAt(i) - '0';
int y = j < 0 ? 0 : num2.charAt(j) - '0';
int sum = (x + y + carry) % 10;
builder.append(sum);
carry = (x + y + carry) / 10;
}
return builder.reverse().toString();
}
}
Loading…
Cancel
Save