1.right view of tree 2.check wheether given binary tre is subtree of binary tree
Sigiloso
1. Right view of the tree: class Solution { public: void printRview(TreeNode *root,int level,int &maxlevel,vector&v) { if(!root)return; if(maxlevelval); maxlevel=level; } printRview(root->right,level+1,maxlevel,v); printRview(root->left,level+1,maxlevel,v); } vector rightSideView(TreeNode* root) { vector v; int maxlevel=0; printRview(root,1,maxlevel,v); return v; } }; 2. Is Subtree: class Solution { public: string preorder(TreeNode *root) { if(!root) return "null"; return "#"+to_string(root->val)+" "+preorder(root->left)+" "+preorder(root->right); } bool isSubtree(TreeNode* s, TreeNode* t) { if(!s and !t) return true; string s1=preorder(s); string s2=preorder(t); if(s1.find(s2)!=string::npos) return true; return false; } };