MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / dfs

Method dfs

Trees/addOneRowToTree.cpp:117–132  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

115class Solution {
116public:
117 void dfs(TreeNode* root, int val, int depth,int k){
118 if(!root)return;
119 if(depth==k+1){
120 TreeNode *templ=new TreeNode(val);
121 TreeNode *l=root->left;
122 root->left=templ;
123 templ->left=l;
124 TreeNode *tempr=new TreeNode(val);
125 TreeNode *r=root->right;
126 root->right=tempr;
127 tempr->right=r;
128 }
129 dfs(root->left,val,depth,k+1);
130 dfs(root->right,val,depth,k+1);
131 return;
132 }
133 TreeNode* addOneRow(TreeNode* root, int val, int depth) {
134 if(depth==1){
135 TreeNode *temp=new TreeNode(val);

Callers

nothing calls this directly

Calls 1

dfsFunction · 0.70

Tested by

no test coverage detected