class Solution {public boolean leafSimilar(TreeNode root1, TreeNode root2) {ArrayList<Integer> li1=new ArrayList<>();ArrayList<Integer> li2=new ArrayList<>();solut(root1,li1);solut(root2,li2);return li1.equals(li2);}void solut(TreeNode root,ArrayList<Integer> li){if(root==null){return;}if(root.left==null&&root.right==null){li.add(root.val);}solut(root.left,li);solut(root.right,li);}
}
class Solution(object):def leafSimilar(self, root1, root2):li1=[]li2=[]def solut(root,li):if root is None:returnif root.left is None and root.right is None:li.append(root.val)solut(root.left,li)solut(root.right,li)solut(root1,li1)solut(root2,li2)return li1==li2