https://leetcode.cn/problems/remove-linked-list-elements/description/
class Solution {
public:
ListNode* removeElements(ListNode* head, int val) {
while (head!=NULL && head->val==val){
head=head->next;
}
ListNode* now=head;
ListNode* pre=head;
while (now){
if (now->val!=val){
pre=now;
now=now->next;
}else{
pre->next=now->next;
now=now->next;
}
}
return head;
}
};
https://leetcode.cn/problems/design-linked-list/description/
class MyLinkedList {
public:
struct Linkednode{
int val;
Linkednode* next;
Linkednode(int val):val(val),next(NULL){}
};
MyLinkedList() {
_dummyHead=new Linkednode(0);
_size=0;
}
int get(int index) {
if (index<0 || index>(_size-1)) return -1;
Linkednode* now=_dummyHead->next;
while (index--){
now=now->next;
}
return now->val;
}
void addAtHead(int val) {
Linkednode* node=new Linkednode(val);
node->next=_dummyHead->next;
_dummyHead->next=node;
_size++;
}
void addAtTail(int val) {
Linkednode* cur=_dummyHead;
Linkednode* last=new Linkednode(val);
while (cur->next!=NULL){
cur=cur->next;
}
cur->next=last;
_size++;
}
void addAtIndex(int index, int val) {
if (index>_size) return ;
if (index<0) index=0;
Linkednode* cur=_dummyHead;
Linkednode* in=new Linkednode(val);
while (index--){
cur=cur->next;
}
in->next=cur->next;
cur->next=in;
_size++;
}
void deleteAtIndex(int index) {
if (index>=_size || index<0) return ;
Linkednode* cur=_dummyHead;
while(index--){
cur=cur->next;
}
Linkednode* tmp=cur->next;
cur->next=cur->next->next;
delete tmp;
tmp=NULL;
_size--;
}
void printLinkedList() {
Linkednode* cur = _dummyHead;
while (cur->next!=NULL) {
cout << cur->next->val << " ";
cur = cur->next;
}
cout << endl;
}
private:
int _size;
Linkednode* _dummyHead;
};
https://www.acwing.com/problem/content/description/5468/
#include <bits/stdc++.h>
using namespace std;
#define lowbit(x) (x& - (x))
#define int long long
int a[100005],INF=2e9;
signed main(){
int n,t=INF;
cin>>n;
for (int i=0;i<n;++i){
cin>>a[i];
t=min(t,a[i]);
}
while (a[t%n]-t>0) t++;
cout<<t%n+1;
}