2.12学习总结

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;
} 
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值