# Java easy to understand solution. Find half boundaries and half leaves first.

• The idea is very simple. We can find the boundaries and leaves in the left subtree first using recursion and put them into a list. And do the same to the right subtree. Using a flag `findBoundry` to check whether the current node is a boundary.
The last two functions can be merged into one.

``````public class Solution {
public List<Integer> boundaryOfBinaryTree(TreeNode root) {
List<Integer> lefthalf = new ArrayList<>();
List<Integer> righthalf = new ArrayList<>();
List<Integer> result = new ArrayList<>();
if(root == null)
return result;
findleft(lefthalf, root.left, true);
findright(righthalf, root.right, true);
return result;
}

public void findleft(List<Integer> list, TreeNode node, boolean findBoundary){
if(node == null)
return;
if(findBoundary || node.left == null && node.right == null)
findleft(list,node.left,findBoundary);
if(findBoundary && node.left == null)
findleft(list,node.right,true);
else
findleft(list,node.right,false);
}
public void findright(List<Integer> list, TreeNode node, boolean findBoundary){
if(node == null)
return;
if(findBoundary || node.left == null && node.right == null)