1. Given a sorted linked list,DeleteAll duplicates such, each element is appear only once. For Example,given1-1-2,return 1-2. Given1-1-2-3-3,return 1-2-3. Zhigiven1-1-1-2-3ListNode* Deleteelements (ListNode *head) { if(head==null&&head->next==NULL)returnHead; ListNode*p=Head; ListNode*q=p->Next; while(q) {if(p->val!=q->val) {ListNode*del=p->Next; while(del!=q) {ListNode*tmp=del->Next; Deletedel; Del=tmp; } P->next=Q; P=Q; Q=q->Next; } Else{Q=q->Next; }} P->next=NULL; returnhead;}2. Print Yang Hui triangle1 1 1 1 2 1 1 3 3 1 1 4 6 4 1input: N, print the first n rows without considering indentationvoidPrintintN) {if(n<=0) return; if(n==1) {cout<<1<<Endl; return; } if(n==2) {Count<<1<<' '<<1<<Endl; return; } Vector<int> res={1,1}; cout<<1<<Endl; cout<<1<<' '<<1<<Endl; for(intI=3; i<=n;++i) {vector<int>tmp; Tmp.push_back (1); for(intj=0; J<res.size ()-1;++j) {Tmp.push_back (Res[j]+res[j+1]); } tmp.push_back (1); Res=tmp; for(Auto a:res) {cout<<a<<' '; } cout<<Endl; }}
American Group Interview algorithm problem