Baidu Software development intern written test:
1. Simulate the short job priority scheduling algorithm, calculate the average waiting time, for example, input [0,2,4,8] means four jobs are 0s to, 2s to, 4s to, 8s to. [2,1,6,3] Represents the run time of four jobs.
Calculates the average wait time. Wait time per job: Actual start time-arrival time. (Non-deprivation)
2. Two sub-structure of the tree, enter two trees A, B, to determine whether B is a sub-tree. The sword refers to offer also has, took out together to do.
/*struct TreeNode {int val; struct TreeNode *left; struct TreeNode *right; TreeNode (int x): Val (x), left (null), right (null) {}};*/classSolution { Public: BOOLIssub (treenode* root1,treenode*Root2) { if(root1==NULL) { if(root2==NULL)return true; Else return false; } if(root2==NULL)return true; if(root1->val!=root2->val)return false; returnIssub (Root1->left,root2->left) &&issub (root1->right,root2->Right ); } BOOLHassubtree (treenode* pRoot1, treenode*PRoot2) { if(proot1==null| | proot2==NULL)return false; BOOLret; RET=issub (PROOT1,PROOT2); if(ret)returnret; if(!ret) ret=hassubtree (proot1->Left,proot2); if(!ret) ret=hassubtree (proot1->Right,proot2); returnret; }};
3. The third Road preface. It seems to be operating system too.
--------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------- --------------------
Sword means offer (Baidu written test)--sub-structure of two fork tree