Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class DZ2Task1 {
- public List<String> binaryTreePaths(TreeNode root) {
- List<String> res = new ArrayList<>();
- if(root == null) return res;
- if(root.left == null && root.right == null) {
- res.add(String.valueOf(root.val));
- return;
- }
- for(String s : binaryTreePaths(root.left)) {
- res.add(String.valueOf(root.val) + "->" + s);
- }
- for(String s : binaryTreePaths(root.right)) {
- res.add(String.valueOf(root.val) + "->" + s);
- }
- return res;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment