# My solution, little long but

• ``````/**
* Definition for a binary tree node.
* public class TreeNode {
*     int val;
*     TreeNode left;
*     TreeNode right;
*     TreeNode(int x) { val = x; }
* }
*/
public class Solution {

public List<String> binaryTreePaths(TreeNode root) {
List <String> retList = new ArrayList<String>();
StringBuffer sb = new StringBuffer();
if(root==null) {
return retList;
}

if(root.left==null && root.right==null) {
sb.append(root.val);
return retList;
}

List<TreeNode> arList = new ArrayList<TreeNode>();
Map <Integer,List> keyMap = new HashMap<Integer,List>();
keyMap.put(new Integer(1),arList);
helper(arList, root);
Set <List> listSet = new HashSet<List>();

for(int i=arList.size()-1;i>=0;i--) {
TreeNode node = arList.get(i);
if(node.left==null && node.right==null) {
List <String> pathList = new ArrayList<String>();
arList.remove(i);
//i++;
}
}

for(int i=arList.size()-1;i>=0;i--) {
TreeNode node = arList.get(i);
familyUnion(node, listSet);
}

Iterator<List> iter = listSet.iterator();
sb.delete(0, sb.length());
while(iter.hasNext()) {
List val = iter.next();
for(int i=0;i<val.size();i++) {
if(i==val.size()-1) {
sb.append(val.get(i));
}
else {
sb.append(val.get(i));
sb.append("->");
}
}
sb.delete(0, sb.length());
}

return retList;
}

public void familyUnion(TreeNode father, Set kids) {
boolean condition1 = false;
boolean condition2 = false;
Iterator <List> iter = kids.iterator();
while(iter.hasNext()) {
List <String> kid = iter.next();
for(int k=0;k<kid.size();k++) {
String val = kid.get(k);
//check if curren node is father
if(father.left!=null   && String.valueOf(father.left.val).equals(val)) {
String temp = val;
// got your father so go back
break;
}
if(father.right!=null  && String.valueOf(father.right.val).equals(val)) {
String temp = val;
// got your father so go back
break;
}
}
}
}

public void helper( List arList ,TreeNode node) {

if(node.left!=null) {
}

if(node.right!=null) {