pull/6/head
yuanguangxin 4 years ago
parent 797687e5d6
commit 31aca682c6

@ -1,8 +1,9 @@
<?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 q215/q347">
<change afterPath="$PROJECT_DIR$/src/栈相关/q316_去除重复字母/Solution.java" afterDir="false" />
<list default="true" id="af7ffdf2-4ddc-4ed6-8222-60ed5acbc2ed" name="Default Changelist" comment="add q316">
<change afterPath="$PROJECT_DIR$/src/递归/q226_翻转二叉树/Solution.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/递归/q226_翻转二叉树/TreeNode.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>
@ -67,11 +68,11 @@
</component>
<component name="RecentsManager">
<key name="CopyClassDialog.RECENTS_KEY">
<recent name="递归.q226_翻转二叉树" />
<recent name="链表操作.q138_复制带随机指针的链表.f2" />
<recent name="链表操作.q138_复制带随机指针的链表.f1" />
<recent name="hash相关.q141_环形链表.f2" />
<recent name="hash相关.q141_环形链表.f1" />
<recent name="树的遍历.q102_二叉树的层次遍历" />
</key>
<key name="CopyFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/src/hash相关" />
@ -281,7 +282,8 @@
<workItem from="1582873496305" duration="10718000" />
<workItem from="1583244406273" duration="200000" />
<workItem from="1583480518824" duration="4257000" />
<workItem from="1583497707004" duration="98000" />
<workItem from="1583497707004" duration="210000" />
<workItem from="1583849488567" duration="658000" />
</task>
<task id="LOCAL-00001" summary="add q5/q7/q172">
<created>1580045439607</created>
@ -605,7 +607,14 @@
<option name="project" value="LOCAL" />
<updated>1582972061183</updated>
</task>
<option name="localTasksCounter" value="47" />
<task id="LOCAL-00047" summary="add q316">
<created>1583497819094</created>
<option name="number" value="00047" />
<option name="presentableId" value="LOCAL-00047" />
<option name="project" value="LOCAL" />
<updated>1583497819094</updated>
</task>
<option name="localTasksCounter" value="48" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
@ -658,7 +667,6 @@
</option>
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="add q53" />
<MESSAGE value="add q54" />
<MESSAGE value="add q23/q101" />
<MESSAGE value="add q94/98/144/145" />
@ -683,7 +691,8 @@
<MESSAGE value="add q138" />
<MESSAGE value="add q56" />
<MESSAGE value="add q215/q347" />
<option name="LAST_COMMIT_MESSAGE" value="add q215/q347" />
<MESSAGE value="add q316" />
<option name="LAST_COMMIT_MESSAGE" value="add q316" />
</component>
<component name="WindowStateProjectService">
<state x="320" y="115" key="#Inspections" timestamp="1581061018990">
@ -698,10 +707,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="1582979530005">
<state x="303" y="50" key="CommitChangelistDialog2" timestamp="1583851362092">
<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="1582979530005" />
<state x="303" y="50" key="CommitChangelistDialog2/0.0.1440.900@0.0.1440.900" timestamp="1583851362092" />
<state x="144" y="78" width="1152" height="720" key="DiffContextDialog" timestamp="1582971909377">
<screen x="0" y="0" width="1440" height="900" />
</state>
@ -756,10 +765,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="1583244442349" />
<state x="320" y="190" key="Vcs.Push.Dialog.v2" timestamp="1582972062261">
<state x="320" y="190" key="Vcs.Push.Dialog.v2" timestamp="1583497821216">
<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="1582972062261" />
<state x="320" y="190" key="Vcs.Push.Dialog.v2/0.0.1440.900@0.0.1440.900" timestamp="1583497821216" />
<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>

@ -67,6 +67,7 @@
* [q21_合并两个有序链表](/src/递归/q21_合并两个有序链表)
* [q101_对称二叉树](/src/递归/q101_对称二叉树)
* [q226_翻转二叉树](/src/递归/q226_翻转二叉树)
* [q236_二叉树的最近公共祖先](/src/递归/q236_二叉树的最近公共祖先)
### 分治法/二分法

@ -0,0 +1,23 @@
package .q226_;
/**
* o(n)
*/
public class Solution {
public TreeNode invertTree(TreeNode root) {
if (root == null) {
return null;
}
TreeNode temp = root.left;
root.left = root.right;
root.right = temp;
if (root.left != null) {
invertTree(root.left);
}
if (root.right != null) {
invertTree(root.right);
}
return root;
}
}

@ -0,0 +1,11 @@
package .q226_;
public class TreeNode {
int val;
TreeNode left;
TreeNode right;
TreeNode(int x) {
val = x;
}
}
Loading…
Cancel
Save