Sword means offer (Baidu written test)--sub-structure of two fork tree

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.