-够了......9、10全是TLE ·-·
-到底怎么样才能够摆脱TLE的命运啊喂!!
-我不想再见到TLE的邪魅笑容了!!!
-大神快帮我敲敲看......到底哪不对了......
——————————前—言——————————
#include<iostream>
using namespace std;
struct ListNode{
int val;
ListNode*next;
ListNode(int x):val(x),next(nullptr){}
};
ListNode*CLL(){
ListNode*head=new ListNode(1);
return head;
}
int FVA(ListNode* head,int targetVal){
ListNode*cur=head;
while(cur!=nullptr){
if(cur->val==targetVal&&cur->next != nullptr){
return cur->next->val;
}
cur=cur->next;
}
return 0;
}
ListNode*IAV(ListNode*head,int targetVal,int newVal){
ListNode*cur=head;
while(cur!=nullptr){
if (cur->val==targetVal){
ListNode*newNode=new ListNode(newVal);
newNode->next=cur->next;
cur->next=newNode;
break;
}
cur=cur->next;
}
return head;
}
ListNode*DAV(ListNode* head,int t){
ListNode*c=head;
while(c!=nullptr){
if(c->val==t&&c->next!=nullptr){
ListNode*toDelete=c->next;
c->next=c->next->next;
delete toDelete;
break;
}
c=c->next;
}
return head;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n,a,x,y;
cin>>n;
ListNode*head=CLL();
while(n--){
cin>>a;
if(a==1){
cin>>x>>y;
head=IAV(head,x,y);
}else if(a==2){
cin>>x;
cout<<FVA(head,x)<<"\n";
}else if(a==3){
cin>>x;
head=DAV(head,x);
}
}
return 0;
}