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. 学习总结21

    2024-02-13 07:34:03       40 阅读
  2. 学习总结

    2024-02-13 07:34:03       45 阅读
  3. 学习总结

    2024-02-13 07:34:03       36 阅读
  4. 学习总结

    2024-02-13 07:34:03       37 阅读
  5. 学习总结

    2024-02-13 07:34:03       34 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-02-13 07:34:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-02-13 07:34:03       100 阅读
  3. 在Django里面运行非项目文件

    2024-02-13 07:34:03       82 阅读
  4. Python语言-面向对象

    2024-02-13 07:34:03       91 阅读

热门阅读

  1. 记录 | C++ #ifdef #endif 条件编译指令

    2024-02-13 07:34:03       56 阅读
  2. c++ STL系列——(三)list

    2024-02-13 07:34:03       53 阅读
  3. ElasticSearch级查询Query DSL下

    2024-02-13 07:34:03       44 阅读
  4. arduino ide esp32 网页按钮异步请求

    2024-02-13 07:34:03       56 阅读
  5. 桥接模式:连接抽象与实现的设计艺术

    2024-02-13 07:34:03       55 阅读
  6. Kotlin:单例模式(项目使用实例)

    2024-02-13 07:34:03       55 阅读
  7. 使用 C++23 从零实现 RISC-V 模拟器(1):最简CPU

    2024-02-13 07:34:03       50 阅读
  8. 面试复盘——9

    2024-02-13 07:34:03       60 阅读
  9. 嵌入式大厂面试题(1)—— CVTE

    2024-02-13 07:34:03       56 阅读
  10. ES实战-分析数据1

    2024-02-13 07:34:03       47 阅读