腾讯百度阿里华为常见算法面试题TOP100(3):链表、栈、特殊技巧

news2024/9/21 22:33:24

之前总结过字节跳动TOP50算法面试题:

字节跳动常见算法面试题top50整理_沉迷单车的追风少年-CSDN博客_字节算法面试题

链表

160.相交链表 

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) {
        // 思路:先计算两个链表的长度lenA、lenB,让长的链表先走(lenA-lenB)步
        // 然后两个链表在同一起跑线上,同时前进直到重叠
        int lenA = 0;
        int lenB = 0;
        ListNode* lenNodeA = headA;
        ListNode* lenNodeB = headB;
        while (lenNodeA) {
            lenA ++;
            lenNodeA = lenNodeA->next;
        }
        while (lenNodeB) {
            lenB ++;
            lenNodeB = lenNodeB->next;
        }
        // 让lenA保持最大长度
        if (lenA < lenB) {
            swap(headA, headB);
            swap(lenA, lenB);
        } 
        int n = lenA - lenB;
        while(n--) {
            headA = headA->next;
        }
        while (headA && headB) {
            if (headA == headB) {
                return headA;
            }
            headA = headA->next;
            headB = headB->next;
        }
        // 无重叠
        return nullptr;
    }
};

206.反转链表 

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    ListNode* reverseList(ListNode* head) {
        if (head == nullptr || head->next == nullptr) {
            return head;
        }
        ListNode* temp; // 保存cur的下一个节点
        ListNode* pre = nullptr;
        while (head) {
            temp = head->next; // 保存下一个节点
            head->next = pre; // 翻转操作
            // 更新pre head指针
            pre = head;
            head = temp;
        }
        return pre;
    }
};

234.回文链表

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    bool isPalindrome(ListNode* head) {
        vector<int> array;
        while (head) {
            array.push_back(head->val);
            head = head->next;
        }
        int i = 0, j = array.size() - 1;
        while (i <= j) {
            if (array[i] != array[j]) {
                return false;
            }
            i++;
            j--;
        }
        return true;
    }
};

141.环形链表

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    bool hasCycle(ListNode *head) {
        if (head == nullptr || head->next == nullptr) {
            return false;
        }
        // 经典快慢指针
        ListNode* fast = head->next;
        ListNode* slow = head;
        while (fast->next && fast->next->next && slow->next) {
            if (fast == slow) {
                return true;
            }
            slow = slow->next;
            fast = fast->next->next;
        }
        return false;
    }
};

142.环形链表II 

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode *detectCycle(ListNode *head) {
        //肯定没有环的情况
        if (head == nullptr || head->next == nullptr) {
            return nullptr;
        }
        ListNode* slow = head;
        ListNode* fast = head;
        bool flag = false;
        while (fast->next && fast->next->next && slow->next) {
            slow = slow->next;
            fast = fast->next->next;
            if (fast == slow) {
                flag = true;
                break;
            }
        }
        // 没有环的情况
        if (!flag) {
            return nullptr;
        }
        //将慢指针归位到头结点
        slow = head;
        //快慢指针以同样的速度再走一遍
        while (slow != fast) {
            slow = slow->next;
            fast = fast->next;
        }
        return slow;
    }
};

21.合并两个有序链表 

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    ListNode* mergeTwoLists(ListNode* list1, ListNode* list2) {
        ListNode* dummy = new ListNode(-1);
        ListNode* cur = dummy;
        while (list1 && list2) {
            if (list1->val > list2->val) {
                cur->next = list2;
                list2 = list2->next;
            } else {
                cur->next = list1;
                list1 = list1->next;
            }
            // 记得移动指针
            cur = cur->next;
        }
        // 合并后 l1 和 l2 最多只有一个还未被合并完,我们直接将链表末尾指向未合并完的链表即可
        if (list1 == nullptr && list2 != nullptr) {
            cur->next = list2;
        } else if (list1 != nullptr && list2 == nullptr) {
            cur->next = list1;
        }

        return dummy->next;
    }
};

2.两数相加 

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
        // 计算长度
        int len1 = 0;
        int len2 = 0;
        ListNode* p = l1;
        while (p->next != nullptr) {
            len1 += 1;
            p = p->next;
        }
        ListNode* q = l2;
        while (q->next != nullptr) {
            len2 += 1;
            q = q->next;
        }
        // 将短的链表补0
        if (len1 < len2) {
            for (int i = 0; i < len2- len1; i++) {
                p->next = new ListNode(0);
                p = p->next;
            }
        } else {
            for (int i = 0; i < len1 - len2; i++) {
                q->next = new ListNode(0);
                q = q->next;
            }
        }
        // 归位
        p = l1;
        q = l2;
        // 记录进位
        bool flag = false;
        ListNode* dummy = new ListNode(-1);
        dummy->next = l1;
        int i = 0;
        // l3移位
        ListNode* w = dummy;
        while (p != nullptr || q != nullptr) {
            i = flag + p->val + q->val;
            flag = i >= 10 ? true : false; 
            w->next = new ListNode(i%10);
            w = w->next;
            p = p->next;
            q = q->next;
        }
        // 最后一位是否进位
        if (flag) {
            w->next = new ListNode(1);
            w = w->next;
        }
        return dummy->next;
    }
};

19.删除链表的倒数第N个结点 

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    ListNode* removeNthFromEnd(ListNode* head, int n) {
        // 快慢指针
        ListNode* fast = head;
        ListNode* slow = head;
        ListNode* dummy = new ListNode(-1);
        dummy->next = head;
        // 快指针先走n步
        while (n--) {
            fast = fast->next;
        }
        // n等于链表长度时特殊处理
        if (fast == nullptr) {
            return head->next;
        }
        // 再一起走到终点
        while (fast != nullptr && fast->next != nullptr) {
            fast = fast->next;
            slow = slow->next;
        }
        slow->next = slow->next->next;
        return dummy->next;
    }
};

 25.k个一组翻转链表 

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode* reverseKGroup(ListNode* head, int k) {
        ListNode* dummy = new ListNode(-1);
        dummy->next = head;
        int lenght = 0;
        while (head) {
            lenght++;
            head = head->next;
        }
        head = dummy->next;
        ListNode* cur = head, *next, *pre = dummy;
        for (int i = 0; i < lenght / k; i++) {
            // 这一步变成反转链表
            for (int j = 0; j < k - 1; j++) {
                next = cur->next;
                cur->next = next->next;
                next->next = pre->next;
                pre->next = next;
            }
            pre = cur;
            cur = pre->next;
        }
        return dummy->next;
    }
};

138.复制带随机指针的链表 

/*
// Definition for a Node.
class Node {
public:
    int val;
    Node* next;
    Node* random;
    
    Node(int _val) {
        val = _val;
        next = NULL;
        random = NULL;
    }
};
*/

class Solution {
public:
    Node* copyRandomList(Node* head) {
        // 用哈希表记录原节点和复制节点的映射关系
        unordered_map<Node*, Node*> hash;
        Node* node = head;
        // 第一步先只复制value,建立映射关系
        while (node) {
            Node* clone = new Node(node->val, nullptr, nullptr);
            hash[node] = clone;
            node = node->next;
        }
        node = head;
        // 根据建立的映射关系复制next和random指针
        while (node) {
            hash[node]->next = hash[node->next];
            hash[node]->random = hash[node->random];
            node = node->next;
        }
        // 返回克隆节点的头节点
        return hash[head];
    }
};

148.排序链表 

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode* sortList(ListNode* head) {
        if(!head||!head->next)
            return head;
        ListNode* pre = head;
        ListNode* slow,*fast;
        slow = head;
        fast = head;
        while(fast&&fast->next){//快慢指针找到中间点
            pre = slow;
            slow = slow->next;
            fast = fast->next->next;
        }
        pre->next = nullptr;//从中间点断开链表
        return mergeTowList(sortList(head),sortList(slow));
    }
    // 归并排序
    ListNode* mergeTowList(ListNode* l1,ListNode* l2){
        if(!l1)
            return l2;
        if(!l2)
            return l1;
        if(l1->val<l2->val){
            l1->next = mergeTowList(l1->next,l2);
            return l1;
        }else{
            l2->next = mergeTowList(l1,l2->next);
            return l2;
        }
    }
};

23.合并K个升序链表 

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    ListNode* mergeKLists(vector<ListNode*>& lists) {
        // 将值放入小顶堆,然后构造链表
        priority_queue<int, vector<int>, greater<int> > p;
        for (auto elem : lists) {
            while (elem != nullptr) {
                p.push(elem->val);
                elem = elem->next;
            }
        }
        ListNode* head = new ListNode(-1);
        ListNode* dummy = head;
        while (!p.empty()) {
            ListNode* temp = new ListNode(p.top());
            p.pop();
            head->next = temp;
            head = head->next;
        }
        return dummy->next;
    }
};

146.LRU缓存 

class LRUCache {
private:    
    int maxsize = 0;
    list<pair<int, int>> cache;
    unordered_map<int, list<pair<int, int>>::iterator > map;
public:
    LRUCache(int capacity) {
        this->maxsize = capacity;
    }
    
    int get(int key) {
        if (map.find(key) == map.end()) {   // 未找到
            return -1;
        }
        // 找到了, 把key对应的移动到链表的最前端
        pair<int, int> p = *map[key];
        cache.erase(map[key]);
        cache.push_front(p);
        // map中更新
        map[key] = cache.begin();
        return p.second;
    }
    
    void put(int key, int value) {
        if (map.find(key) == map.end()) {
            if (cache.size() == maxsize) { // 满员后删除链表末尾最少使用的
                map.erase(cache.back().first);
                cache.pop_back();
            }
            cache.push_front(make_pair(key, value));
            map[key] = cache.begin();
        } else {   // 未满员只需把key对应的移动到链表的最前端表示刚使用过
            cache.erase(map[key]);
            cache.push_front(make_pair(key, value));
            map[key] = cache.begin();
        }
    }
};

/**
 * Your LRUCache object will be instantiated and called as such:
 * LRUCache* obj = new LRUCache(capacity);
 * int param_1 = obj->get(key);
 * obj->put(key,value);
 */

20.有效的括号

class Solution {
public:
    bool isValid(string s) {
        stack<char> sta;
        for (auto elem : s) {
            if (elem == '(' || elem == '[' || elem == '{') {
                sta.push(elem);
            } else if (elem == ')' && !sta.empty() && sta.top() == '(') {
                sta.pop();
            } else if (elem == '}' && !sta.empty() && sta.top() == '{') {
                sta.pop();
            } else if (elem == ']' && !sta.empty() && sta.top() == '[') {
                sta.pop();
            } else {
                sta.push(elem);
            }
        }
        return sta.empty();
    }
};

155.最小栈

class MinStack {
private:
    // 用一个最小栈维护最小值
    stack<int> sta;
    stack<int> min_sta;

public:
    MinStack() {
        
    }
    
    void push(int val) {
        sta.push(val);
        if (min_sta.empty() || sta.top() <= min_sta.top()) {
            min_sta.push(sta.top());
        }
    }
    
    void pop() {
        if (!sta.empty()) {
            if (sta.top() == min_sta.top()) {
                min_sta.pop();
            }
            sta.pop();
        }
    }
    
    int top() {
        return sta.top();
    }
    
    int getMin() {
        return min_sta.top();
    }
};

/**
 * Your MinStack object will be instantiated and called as such:
 * MinStack* obj = new MinStack();
 * obj->push(val);
 * obj->pop();
 * int param_3 = obj->top();
 * int param_4 = obj->getMin();
 */

394.字符串解码 

class Solution {
public:
    string decodeString(string s) {
        string ans = "";
        // 第一个栈用来存放数字
        stack<int> nums;
        // 第二个栈用来存放字符串
        stack<string> strs;
        int num = 0;
        for (int i = 0; i < s.size(); i++) {
            if (s[i] >= '0' && s[i] <= '9') {
                num = num * 10 + s[i] - '0';
            } else if ((s[i] >= 'A' && s[i] <= 'Z') || (s[i] >= 'a' && s[i] <= 'z')) {
                ans += s[i];
            } else if (s[i] == '[') { //将‘[’前的数字压入nums栈内,字母字符串压入strs栈内
                nums.push(num);
                num = 0;
                strs.push(ans);
                ans = "";
            } else if (s[i] == ']') { // 与'['匹配出栈
                int times = nums.top();
                nums.pop();
                for (int j = 0; j < times; j++) {
                    strs.top() += ans;
                }
                ans = strs.top();
                strs.pop();
            }
        } 
        return ans;
    }
};

739.每日温度 

class Solution {
public:
    vector<int> dailyTemperatures(vector<int>& temperatures) {
        /* 经典单调栈
        维护递减栈,后入栈的元素总比栈顶元素小。
        比对当前元素与栈顶元素的大小
        若当前元素 < 栈顶元素:入栈
        若当前元素 > 栈顶元素:弹出栈顶元素,记录两者下标差值即为所求天数
        */
        vector<int> ans(temperatures.size(), 0);
        stack<int> sta;     // 维护一个递增栈
        for (int i = 0; i < temperatures.size(); i++) {
            while (!sta.empty() && temperatures[i] > temperatures[sta.top()]) {
                ans[sta.top()] = i - sta.top();
                sta.pop();
            }
            sta.push(i);
        }
        return ans;
    }
};

84.柱状图中最大的矩形

暴力解法,会超时:

class Solution {
public:
    int largestRectangleArea(vector<int>& heights) {
        // 找左右两边第一个小于当前的柱子作为边界点,会超时,需要用单调栈优化
        int ans = 0;
        for (int i = 0; i < heights.size(); i++) {
            int w = 1;
            int j = i;
            while (--j >= 0 && heights[j] >= heights[i]) {
                w++;
            }
            j = i;
            while (++j < heights.size() && heights[j] >= heights[i]) {
                w++;
            }
            ans = max(ans, w * heights[i]);
        }
        return ans;
    }
};

单调栈解法:

class Solution {
public:
    int largestRectangleArea(vector<int>& heights) {
        // 单调栈, 找每个柱子左右两边第一个小于该柱子的柱子
        int ans = 0;
        // 在柱体数组的头和尾加了两个高度为 0 的柱体
        heights.push_back(0);
        heights.insert(heights.begin(), 0);
        stack<int> sta;
        sta.push(0);
        for (int i = 0; i < heights.size(); i++) {
            // 对栈中柱体来说,栈中的下一个柱体就是其「左边第一个小于自身的柱体」
            // 若当前柱体i的高度小于栈顶柱体的高度,说明i是栈顶柱体的「右边第一个小于栈顶柱体的柱体」
            while (heights[i] < heights[sta.top()]) {
                int h = heights[sta.top()];
                sta.pop();
                int w = i - sta.top() - 1;
                ans = max(ans, w * h);
            }
            sta.push(i);
        }
        return ans;
    }
};

技巧类

136.只出现一次的数字

class Solution {
public:
    int singleNumber(vector<int>& nums) {
        // 位运算 
        // 同样的数字或运算后等于0, 所以最后剩下来的数字一定是只出现过一次的
        int ans = nums[0];
        for (int i = 1; i < nums.size(); i++) {
            ans ^= nums[i];
        }
        return ans;
    }
};

169.多数元素

class Solution {
public:
    int majorityElement(vector<int>& nums) {
        // 摩尔投票法
        // 遍历后面的数如果相同则count+1,不同则减一
        // 当count为0时则更换新的数字为候选数(成立前提:有出现次数大于n/2的数存在)
        int ans = nums[0];
        int count = 0;
        for (int i = 0; i < nums.size(); i++) {
            if (count == 0) {
                ans = nums[i];
            }
            if (ans == nums[i]) {
                count ++;
            } else {
                count --;
            }
        }
        return ans;
    }
};

75.颜色分类 

class Solution {
public:
    void sortColors(vector<int>& nums) {
        // 三指针解法
        int cur = 0, left = 0, right = nums.size() - 1;
        while (cur <= right) {
            if (nums[cur] == 0) {
                swap(nums[cur++], nums[left++]);
            } else if (nums[cur] == 2) {
                swap(nums[cur], nums[right--]);
            } else{
                cur ++;
            }
        }
        return;
    }
};

31.下一个排列

class Solution {
public:
    void nextPermutation(vector<int>& nums) {
        // 双指针两边遍历法
        // 先找到右边第一个非升序的数
        // 再找右边第一个大于刚才找的非降序的数
        // 最后重排右边找到的那个数到数组末尾区间
        int i = nums.size() - 2, j = nums.size() - 1;
        while (i >=0 && nums[i+1] <= nums[i]) {
            i--;
        }
        if (i >= 0) {
            while (j >= 0 && nums[j] <= nums[i]) {
                j--;
            }
            swap(nums[i], nums[j]);
        }
        sort(nums.begin()+i+1, nums.end());
        return;
    }
};

287.寻找重复数

class Solution {
public:
    int findDuplicate(vector<int>& nums) {
        /**
        快慢指针思想, fast 和 slow 是指针, nums[slow] 表示取指针对应的元素
        注意 nums 数组中的数字都是在 1 到 n 之间的(在数组中进行游走不会越界),
        因为有重复数字的出现, 所以这个游走必然是成环的, 环的入口就是重复的元素, 
        即按照寻找链表环入口的思路来做
        **/
        int fast = 0, slow = 0;
        while (true) {
            fast = nums[nums[fast]];
            slow = nums[slow];
            if (slow == fast) {
                fast = 0;
                while (nums[slow] != nums[fast]) {
                    fast = nums[fast];
                    slow = nums[slow];
                }
                return nums[slow];
            }
        }
    }
};

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2141910.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

29 线性表 · 队列

目录 一、概念与结构 &#xff08;一&#xff09;概念 1、队列 2、入队列 3、出队列 &#xff08;二&#xff09;底层结构 二、队列的实现 三、队列的算法题 &#xff08;一&#xff09;用队列实现栈 &#xff08;二&#xff09;用栈实现队列 &#xff08;三&#xf…

基于AG32 的USB转以太网方案

如何通过USB转以太网标准模块&#xff1f; AG32支持USB FSOTG和以太网MAC&#xff0c;并且提供了标准例程&#xff0c;包括网络Lwip和USB的开发例程&#xff0c;上层应用调tinyUSB的接口即可。 以下是AG32VF407VG的引脚定义&#xff0c;支持USB外设。 LQFP-100Pin nameAG32VFx…

简单了解Maven与安装

Maven 1.Maven 简介 Maven 是 Apache 软件基金会&#xff08;国外组织&#xff0c;专门维护开源项目&#xff09;的一个开源项目, 是一个优秀的项目构建工具, 它用来帮助开发者管理项目中的 jar, 以及 jar 之间的依赖关系(在A.jar文件中用到了B.jar)、 完成项目的编译&am…

圆环加载效果

效果预览 代码实现 from PyQt5.QtCore import QSize, pyqtProperty, QTimer, Qt, QThread, pyqtSignal from PyQt5.QtGui import QColor, QPainter from PyQt5.QtWidgets import QApplication, QWidget, QHBoxLayout, QPushButton, QVBoxLayout, QLabel, QGridLayoutclass Cir…

Rust使用Actix-web和SeaORM库开发WebAPI通过Swagger UI查看接口文档

本文将介绍Rust语言使用Actix-web和SeaORM库&#xff0c;数据库使用PostgreSQL&#xff0c;开发增删改查项目&#xff0c;同时可以通过Swagger UI查看接口文档和查看标准Rust文档 开始项目 首先创建新项目&#xff0c;名称为rusty_crab_api cargo new rusty_crab_apiCargo.t…

Nuxt Kit 中的页面和路由管理

title: Nuxt Kit 中的页面和路由管理 date: 2024/9/17 updated: 2024/9/17 author: cmdragon excerpt: 摘要:本文介绍了Nuxt Kit中页面和路由管理的高级功能,包括extendPages自定义页面路由、extendRouteRules定义复杂路由逻辑及addRouteMiddleware注册路由中间件。通过这…

Html css样式总结

1.Html css样式总结 1.1. 定位position 布局是html中非常重要的一部分&#xff0c;而定位在页面布局中也是使用频率很高的方法&#xff0c;本章节为定位在布局中的使用技巧和注意事项。   position定位有4个属性&#xff0c;分别是static(默认&#xff09;&#xff0c;absol…

第四天旅游线路预览——从换乘中心到白哈巴村

第四天&#xff1a;从贾登峪到喀纳斯风景区入口&#xff0c;晚上住宿贾登峪&#xff1b; 换乘中心有4 路车&#xff0c;喀纳斯③号车&#xff0c;去白哈巴村&#xff0c;路程时长约40分钟&#xff1b; 将上面的的行程安排进行动态展示&#xff0c;具体步骤见”Google earth st…

用Spring Boot搭建的读书笔记分享平台

第1章 绪论 1.1课题背景 计算机的普及和互联网时代的到来使信息的发布和传播更加方便快捷。用户可以通过计算机上的浏览器访问多个应用系统&#xff0c;从中获取一些可以满足用户需求的管理系统。网站系统有时更像是一个大型“展示平台”&#xff0c;用户可以选择所需的信息进入…

【Spring Security系列】如何用Spring Security集成手机验证码登录?五分钟搞定!

作者&#xff1a;后端小肥肠 &#x1f347; 我写过的文章中的相关代码放到了gitee&#xff0c;地址&#xff1a;xfc-fdw-cloud: 公共解决方案 &#x1f34a; 有疑问可私信或评论区联系我。 &#x1f951; 创作不易未经允许严禁转载。 姊妹篇&#xff1a; 【Spring Security系列…

拖拽排序的实现示例demo

拖拽排序的实现示例demo 文章说明核心代码示例效果展示 文章说明 文章主要为了学习拖拽排序的实现思路&#xff0c;并且采用此示例效果来进一步理解Flip动画的使用 参考渡一前端袁老师的讲解视频 核心代码 页面源码&#xff0c;拖拽排序的实现代码并不复杂&#xff0c;但是可以…

我的标志:奇特的头像

<!DOCTYPE html> <html lang"zh-CN"> <head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-scale1.0"><title>与妖为邻</title><style>figure.log…

C++11(4)

万众瞩目的C11特辑来了&#xff0c;本章将继续讲解C11更新的内容&#xff0c;不过C11的内容也快接近尾声了。 目录 10。lambda表达式 11。lambda捕捉列表[] 捕捉列表说明 lambda捕捉列表实际应用 10。lambda表达式 #include<iostream> using namespace std; #inclu…

手把手教你:在微信小程序中加载map并实现拖拽添加标记定位

本文将为大家详细介绍如何在微信小程序中加载map组件&#xff0c;并实现拖拽标记定位功能。 实现步骤 1、首先&#xff0c;我们需要在项目的app.json文件中添加map组件的相关配置。如下所示&#xff1a; {"pages": ["pages/index/index"],"permiss…

robomimic基础教程(三)——自带算法

robomimic自带几个高质量的离线学习算法的实现&#xff0c;包括模仿学习和强化学习&#xff0c;并提供相关工具来辅助你轻松构建自己的学习算法。 一、模仿学习&#xff08;Imitation Learning&#xff09; 1. BC (Behavioral Cloning) Vanilla Behavioral Cloning, 旨在通过…

使用knn算法对iris数据集进行分类

程序功能 使用 scikit-learn 库中的鸢尾花数据集&#xff08;Iris dataset&#xff09;&#xff0c;并基于 KNN&#xff08;K-Nearest Neighbors&#xff0c;K近邻&#xff09;算法进行分类&#xff0c;最后评估模型的准确率。 代码 from sklearn import datasets# 加载鸢尾…

链表在开空间时候出现的问题

题目&#xff1a; 第一种写法完整答案&#xff1a; 第二种写法完整答案&#xff1a;

【机器学习】--- 自监督学习

1. 引言 机器学习近年来的发展迅猛&#xff0c;许多领域都在不断产生新的突破。在监督学习和无监督学习之外&#xff0c;自监督学习&#xff08;Self-Supervised Learning, SSL&#xff09;作为一种新兴的学习范式&#xff0c;逐渐成为机器学习研究的热门话题之一。自监督学习…

【C++题解】1996. 每个小组的最大年龄

欢迎关注本专栏《C从零基础到信奥赛入门级&#xff08;CSP-J&#xff09;》 问题&#xff1a;1996. 每个小组的最大年龄 类型&#xff1a;二维数组 题目描述&#xff1a; 同学们在操场上排成了一个 n 行 m 列的队形&#xff0c;每行的同学属于一个小组&#xff0c;请问每个小…

PCIe进阶之TL:Completion Rules TLP Prefix Rules

1 Completion Rules & TLP Prefix Rules 1.1 Completion Rules 所有的 Read、Non-Posted Write 和 AtomicOp Request 都需要返回一个 Completion。Completion 有两种类型:一种带数据负载的,一种不带数据负载的。以下各节定义了 Completion header 中每个字段的规则。 C…