inorder and indexOf solution( add char at begin and end to split)


  • 0
    T
    /**
     * Definition for a binary tree node.
     * public class TreeNode {
     *     public int val;
     *     public TreeNode left;
     *     public TreeNode right;
     *     public TreeNode(int x) { val = x; }
     * }
     */
    public class Solution {
        public bool IsSubtree(TreeNode s, TreeNode t) {
            return BuildInorder(s).IndexOf(BuildInorder(t)) != -1;
        }
        
        private string BuildInorder(TreeNode root){
            if(root == null)
                return "#";
                
            return "|"+BuildInorder(root.left)+","+root.val+","+BuildInorder(root.right)+"|";
        }
    }
    

  • 0
    D

    @tangalai what are "s_r" & "t_r" used for?


  • 0
    T

    @Datochi Not need, just want to print. will remove. thanks


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.