Skip to content

Commit

Permalink
0727
Browse files Browse the repository at this point in the history
  • Loading branch information
eastplainzhang committed Jul 27, 2021
1 parent e6c9875 commit 8fadc13
Show file tree
Hide file tree
Showing 18 changed files with 740 additions and 1 deletion.
2 changes: 1 addition & 1 deletion leetcode/.idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions topcode/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions topcode/.idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions topcode/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions topcode/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions topcode/.idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions topcode/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions topcode/eastplain/eastplain.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
26 changes: 26 additions & 0 deletions topcode/eastplain/src/infrastructure/Node.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package infrastructure;

import java.util.List;

/**
* 定义 N叉树的结构
*
* @author EastPlain
* @date 2021/7/27 22:38
*/
public class Node {

public int val;
public List<Node> children;

public Node() {}

public Node(int _val) {
val = _val;
}

public Node(int _val, List<Node> _children) {
val = _val;
children = _children;
}
}
20 changes: 20 additions & 0 deletions topcode/eastplain/src/infrastructure/TreeNode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package infrastructure;

/**
* 定义 二叉树的结构
*
* @author EastPlain
* @date 2021/7/26 21:52
*/
public class TreeNode {

public int val;
public TreeNode left;
public TreeNode right;

public TreeNode(int val, TreeNode left, TreeNode right) {
this.val = val;
this.left = left;
this.right = right;
}
}
60 changes: 60 additions & 0 deletions topcode/eastplain/src/method/BinaryTreeInorder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package method;

import infrastructure.TreeNode;

import javax.print.DocFlavor;
import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

/**
* 二叉树的中序遍历
* # lc0094
*
* @author EastPlain
* @date 2021/7/26 23:18
*/
public class BinaryTreeInorder {

/**
* 递归法
*/
public List<Integer> recur(TreeNode root) {

return null;
}

/**
* 迭代法
*/
public List<Integer> iteration(TreeNode root) {

Stack<TreeNode> stack = new Stack<>();
List<Integer> ans = new ArrayList<>();

if (root == null) {
return ans;
}

TreeNode current = root;

while (! stack.isEmpty() || current != null) {

while (current != null) {
stack.push(current);
current = current.left;
}

TreeNode node = stack.pop();
ans.add(node.val);

if (node.right != null) {
stack.push(node.right);
}
}

return ans;
}
}


53 changes: 53 additions & 0 deletions topcode/eastplain/src/method/BinaryTreeLayer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package method;

import infrastructure.TreeNode;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

/**
* 二叉树的层序遍历
* # lc0102
*
* @author EastPlain
* @date 2021/7/26 23:37
*/
public class BinaryTreeLayer {

public List<List<Integer>> method(TreeNode root) {

List<List<Integer>> ans = new ArrayList<>();
Queue<TreeNode> queue = new LinkedList<>();

if (root == null) {
return ans;
}

queue.add(root);

while (! queue.isEmpty()) {

int size = queue.size();
List<Integer> temp = new ArrayList<>();

for (int i = 0; i < size; i++) {
TreeNode current = queue.remove();
temp.add(current.val);

if (current.left != null) {
queue.add(current.left);
}

if (current.right != null) {
queue.add(current.right);
}
}

ans.add(temp);
}

return ans;
}
}
Loading

0 comments on commit 8fadc13

Please sign in to comment.