Serailize and Deserialize N-Ary Tree | Leetcode Solution

preview_player
Показать описание




.
.
.
Happy Programming !!! Pep it up 😍🤩
.
.
.
#pepcoding #code #coder #codinglife #programming #coding #java #freeresources #datastrucutres #pepcode #competitive #competitiveprogramming #softwareengineer #engineering #engineer
Рекомендации по теме
Комментарии
Автор

I have implemented the deserialize function using a stack and it worked for all test cases on nados:

public static Node deserialize(String str) {
String[] arr=str.split(", ");
Stack<Node> st=new Stack<>();
Node root=new
st.push(root);
int i=1;
while(st.size()>0 && i<arr.length){
Node rem=st.peek();
if(st.size()>1 && rem==null){
st.pop();
st.pop(); //removing the null value and the value that has no children
}else{
if(arr[i].equals("null")){
st.push(null);
continue;
}
Node child=new
rem.children.add(child); //adding the next number as child of current st.peek()
st.push(child);
}
i++; //moving to next number
}
return root;
}

architsharma
Автор

sir your videos are best .please teach dynamic programic from basic to advance .

soumya
Автор

sir yha pr khudka stack banane ka inuition kaise aya, maine khudse dfs lgane mai 30 min bekar kiye the, ye special type ka ques hai kya

mickyman
Автор

intro song was expected from pepcoding😂

brutal
Автор

Trees ki kitni videos dalni baaki hai abhi level 2 me?

mridulgupta
join shbcf.ru