Ott
BAN USER
public int MaxLevel(Node root){
if(root==null)
return -1;
//search the entire tree level by level
Queue<Node> cur = new Queue<Node>();
cur.offer(root);
int max = 0;
while((int size = cur.size())!=0){
max = size>max?size:max;
Queue<Node> parent = cur;
cur = new Queue<Node>();
while(parent.peek()!=null){
Node temp = parent.poll();
if(temp.left!=null)
cur.offer(temp.left);
if(temp.right!=null)
cur.offer(temp.right);
}
}
return max;
}
//recursion
public int getDepth(Node root){
if(root==null)
return 0;
else return max(getDepth(root->left), getDepth(root->right))+1;
}
public void getLevelInfo(Node root, int[] levelcount, int level){
if(root==null)
return;
levelcount[level]++;
getlevelInfo(root->left, levelcount, level++);
getlevelInfo(root->right, levelcount, level++);
return;
}
public int findMax(int[] array){
int max = INT_MIN;
for(int i=0;i<array.length;i++)
max = array[i]>max?arry[i]:max;
return max;
}
public int main(Node root){
int[] levelcount = new int[getDepth(root)];
getLevelInfo(root,levelcount,0);
print(findMax(levelcount));
return 0;
}
Repbarrietrosado, abc at ABC TECH SUPPORT
Hi, I am Barrie, from Ualapue USA. I believe that every challenge has a solution - and I take great satisfaction ...
Repshirleygause93, Analyst at Absolute Softech Ltd
Hi, I am Shirley from taxes, Conducted a re-profiling project which enabled our customers to receive orders more efficiently.Planning ...
Repelisahbuff, Apple Phone Number available 24/7 for our Customers at Altera
I have previous work experience in a customer focused environment. I like to Enjoy my Free Time Playing football.I ...
Repmonicaralvarado94, Korean Air Change Flight at Athena Health
I am fond of reading stories then reading articles which are all about a story of a beautiful nature and ...
public Node rotate(Node root, int n){
- Ott February 14, 2013Node slow = root;
Node fast = root;
for(int i=n;i>0;i--){
fast = fast.next;
if(fast==null)
return null;
}
while(fast->next!=null){
fast=fast->next;
slow=slow->next;
}
fast->next = root;
root = slow->next;
slow->next = null;
return root;
}