Leetcode C++ 链表

Ubuntu24.04LTS上Ollama GPU加速配置指南:从驱动安装到多卡均衡负载 本文详细介绍了在Ubuntu24.04LTS系统上配置Ollama GPU加速的完整指南,包括NVIDIA驱动安装、CUDA Toolkit配置、Ollama在线与离线安装方法,以及多GPU负载均衡优化策略。通过实战案例和性能调优建议,帮助开发者充分利用硬件资源提升大型语言模型的运行效率。 阅读详情

Leetecode 206

206. Reverse Linked List

Reverse a singly linked list.
Example:
Input: 1->2->3->4->5->NULL
Output: 5->4->3->2->1->NULL

  • 思路:
    首先设定两个指针,pre和curr,翻转指针就是将curr的next指向pre,但是由于链表是单向的,因此反转后就无法获得下一个指针,所以还需要设定第三个指针next存储curr翻转前的下一个指针。
ListNode* reverseList(ListNode* head) {
    if (!head) // head = nullptr
        return head;
    ListNode* pre = nullptr;
    ListNode* curr = head;
    while (curr) {
        ListNode* next = curr->next;
        curr->next = pre;
        // move
        pre = curr;
        curr = next;
    }
    return pre;
}

Leetecode 92

92. Reverse Linked List II

Reverse a linked list from position m to n. Do it in one-pass.
Note: 1 ≤ m ≤ n ≤ length of list.
Example:
Input: 1->2->3->4->5->NULL, m = 2, n = 4
Output: 1->4->3->2->5->NULL

  • 思路:
    使用链表轮转的方法解决链表翻转的问题。
ListNode* reverseBetween(ListNode* head, int m, int n) {
    // for m = 1
    ListNode* dummy = new ListNode();
    dummy->next = head;
    
    ListNode* prev = dummy;
    ListNode* curr = prev->next;
    ListNode* next = curr->next;
    
    // start node id = m (start from 1)
    for (int id = 1; id < m; ++id) {
        prev = prev->next;
        curr = curr->next;
        next = next->next;
    }
    
    // rotate
    for (int id = 0; id < n - m; ++id) {
        curr->next = next->next;
        next->next = prev->next;
        prev->next = next;
        next = curr->next;
    }
    return dummy->next;
}

Leetecode 86

86. Partition List

Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.
You should preserve the original relative order of the nodes in each of the two partitions.
Example:
Input: head = 1->4->3->2->5->2, x = 3
Output: 1->2->2->4->3->5

  • 思路:
    使用轮换方法,将小于x的节点轮换到左边,保持顺序不变。由于使用轮换所以需要3个指针。
    start:指向最后一个大于等于x的node;
    prev:指向最后一个小于x的node;
    then:指向新发现的小于x的node;
  1. 条件1:当start值小于x时,3个指针同时前移
  2. 条件2:当start值大于等于x时,此时判断then的值,如果then的值同样大于等于x时同时后移;
  3. 条件3:如果then值小于x,那么进行轮换操作;
  4. 后处理:考虑轮换后start是否为最后节点,如果不是最后节点,那么还要考虑start下一节点的值来判断start是否需要后移;
ListNode* partition(ListNode* head, int x) {
	// 如果当前List是空或只有一个node,直接返回
    if (!head || !head->next)
        return head;
    // 构造一个虚拟节点
    ListNode* dummy = new ListNode();
    dummy->next = head;
    // 因为使用轮转方法,所以需要prev, start和the指针
    ListNode* prev = dummy;
    ListNode* start = prev->next;
    ListNode* then = start->next;
    
    while (then) {
        // 条件1(只有初始时才可能满足):start值小于x,那么所有指针向后移动
        if (start->val < x) {
            prev = prev->next;
            start = start->next;
            then = then->next;
        } else if (start->val >= x && then->val >= x) { // 条件2:此时prev不移动,start和then后移
            start = start->next;
            then = then->next;
        } else if (start->val >= x && then->val < x) { // 条件3:此时进行轮换操作
            // 轮换操作
            start->next = then->next;
            then->next = prev->next;
            prev->next = then;
            // 操作后处理,要考虑轮换后start是否为最后节点
            prev = prev->next;
            if (start->next) { // 轮换后如果start的next节点存在
                if (start->next->val >= x) // 如果start的next存在,根据值大小判断start是否后移
                    start = start->next;
                then = start->next;
            } else // start是最后一个节点
                then = nullptr;
        }
    }
    ListNode* res = dummy->next;
    delete dummy;
    return res;
}

Leetecode 328

328. Odd Even Linked List

Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes.
You should try to do it in place. The program should run in O(1) space complexity and O(nodes) time complexity.
Example 1:
Input: 1->2->3->4->5->NULL
Output: 1->3->5->2->4->NULL

  • 思路:
    使用两个指针交替指向对方的next然后再前进一步的方法,因为连接后even链表再尾部,因此终止条件设置为even本身或其next为nullptr时终止。由于要连接两个链表,所以要首先保存被连接的链表的第一个元素的指针。
ListNode* oddEvenList(ListNode* head) {
    if (!head || !head->next)
        return head;
    ListNode* odd = head;
    ListNode* even = head->next;
    ListNode* temp = even; // for link odd and even finally
    
    while (even && even->next) {
        odd->next = even->next;
        odd = odd->next;
        even->next = odd->next;
        even = even->next;
    }
    odd->next = temp;
    return head;
    
}

Leetecode 2

2. Add Two Numbers

You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list.
You may assume the two numbers do not contain any leading zero, except the number 0 itself.
Example 1:
Input: l1 = [2,4,3], l2 = [5,6,4]
Output: [7,0,8]
Explanation: 342 + 465 = 807.

  • 思路:
  1. 使用dummy head指向存储结果的新List的头指针,可以统一循环中指针向后移动的语句;
  2. 在while开始处new ListNode,保证新List长度和l1或l2相同,便于后期处理;
  3. 注意循环结束后如果flag位是1,那么需要添加新的节点,存储flag位;
  4. 补上nullptr;
ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
    ListNode* res = new ListNode();
    ListNode* start = res;
    int flag = 0;
    int new_val = 0;
    while (l1 || l2) {
        start->next = new ListNode();
        start = start->next;
        int l1_val = l1 ? l1->val : 0;
        int l2_val = l2 ? l2->val : 0;
        
        int sum = l1_val + l2_val + flag;
        new_val = sum % 10;
        flag = sum / 10;
        start->val = new_val;
        
        if (l1)
            l1 = l1->next;
        if (l2)
            l2 = l2->next;  
    }
    if (flag) {
        start->next = new ListNode();
        start = start->next;
        start->val = flag;
    }
    start->next = nullptr;
    return res->next;
}

Leetecode 445

445. Add Two Numbers II

You are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.
You may assume the two numbers do not contain any leading zero, except the number 0 itself.
Follow up:
What if you cannot modify the input lists? In other words, reversing the lists is not allowed.
Example:
Input: (7 -> 2 -> 4 -> 3) + (5 -> 6 -> 4)
Output: 7 -> 8 -> 0 -> 7

  • 思路:
  1. 将list压入栈中,实现元素反转;
  2. 弹出栈然后相加,注意增加flag存储溢出(类似Leetcode 2);
  3. 如果存储结果到List中,那么需要反转结果List;如果存储结果到stack中,那么通过结果stack再直接构造List即可。
ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
    // push into stack
    stack<int> s1, s2, res;
    while (l1) {
        s1.push(l1->val);
        l1 = l1->next;
    }
    while (l2) {
        s2.push(l2->val);
        l2 = l2->next;
    }
    
    /*
    ListNode* dummy = new ListNode();
    ListNode* curr = dummy;
    */
    // add
    int flag = 0;
    int sum = 0;
    while (!s1.empty() || !s2.empty()) {
        //curr->next = new ListNode();
        //curr = curr->next;
        
        int s1_val = s1.empty() ? 0 : s1.top();
        int s2_val = s2.empty() ? 0 : s2.top();
        
        int temp = s1_val + s2_val + flag;
        sum = temp % 10;
        flag = temp / 10;
        //curr->val = sum;
        res.push(sum);
        
        if (!s1.empty())
            s1.pop();
        if (!s2.empty())
            s2.pop();
    }
    if (flag) {
        /*
        curr->next = new ListNode();
        curr = curr->next;
        curr->val = flag;
        */
        res.push(flag);
    }
    //curr->next = nullptr;
    
    /*
    // reverse result
    curr = dummy->next;
    ListNode* next = curr->next;
    while (next) {
        curr->next = next->next;
        next->next = dummy->next;
        dummy->next = next;
        
        next = curr->next;
    }
    return dummy->next;
    */
    // create result list by res stack
    ListNode* res_dummy = new ListNode();
    ListNode* res_curr = res_dummy;
    while (!res.empty()) {
        res_curr->next = new ListNode();
        res_curr = res_curr->next;
        res_curr->val = res.top();
        res.pop();
    }
    res_curr->next = nullptr;
    return res_dummy->next;
}

Leetecode 82

82. Remove Duplicates from Sorted List II

Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.
Return the linked list sorted as well.
Example 1:
Input: 1->2->3->3->4->4->5
Output: 1->2->5
Example 2:
Input: 1->1->1->2->3
Output: 2->3

  • 思路1:
    因为设计节点的删除,所以首先构造虚拟头指针,并分别设置prev、curr和next指针。
    分所有情况讨论,条件分别为:curr与next是否相邻、next是否为空、curr值与next值是否相等。
    因为值相等需要next不能为空,因此将curr与next是否相邻作为最外层条件。
ListNode* deleteDuplicates(ListNode* head) {
    if (!head || !head->next) 
        return head;
    ListNode* dummy = new ListNode();
    dummy->next = head;
    ListNode* prev = dummy;
    ListNode* curr = prev->next;
    ListNode* next = curr->next;
    
    /*
    1. curr and next are adjcent && next is null;
    2. curr and next are adjcent && next is not null && curr->val = next->val;
    3. curr and next are adjcent && next is not null && curr->val != next->val;
    4. curr and next are NOT adjcent && next is null;
    5. curr and next are NOT adjcent && next is not null && curr->val = next->val;
    6. curr and next are NOT adjcent && next is not null && curr->val != next->val;
    */
    while (curr) {
        if (curr->next == next) {// curr and next are adjcent
            if (!next) { // next is nullptr (1)
                curr = curr->next; // curr is nullptr now
            } else { // next is NOT nullptr
                if (curr->val == next->val) { // curr->val = next->val (2)
                    next = next->next;
                } else { // curr->val != next->val (3)
                    prev = prev->next;
                    curr = curr->next;
                    next = next->next;
                }
            }
        } else { // curr and next are NOT adjcent
            if (!next) { // next is nullptr (4)
                prev->next = next;
                ListNode* del = curr;
                while (del != next) {
                    curr = curr->next;
                    delete del;
                    del = curr;
                }
            } else { // next is NOT nullptr
                if (curr->val == next->val) { // curr->val = next->val (5)
                    next = next->next;
                } else { // curr->val != next->val (6)
                    prev->next = next;
                    ListNode* del = curr;
                    while (del != next) {
                        curr = curr->next;
                        delete del;
                        del = curr;
                    }
                    next = next->next;
                }
            }
            
        }                  
    }
    return dummy->next;
}

*思路2:
这个思路比较简单,首先建立一个ListNode虚拟节点,然后通过判断head与head->next是否相同,相同则head向后移动,不同则使用虚拟节点将head串起来。
实现可参考连接.

Leetecode 24

24. Swap Nodes in Pairs

Given a linked list, swap every two adjacent nodes and return its head.
You may not modify the values in the list’s nodes. Only nodes itself may be changed.
Example1:
Input: head = [1,2,3,4]
Output: [2,1,4,3]
Example 2:
Input: head = []
Output: []
Example 3:
Input: head = [1]
Output: [1]

  • 思路:
  1. 交换List中两节点(curr和next);
  2. 交换后prev和curr节点指针向后移动两位;
  3. 判断终止条件,就是要保证带交换的两个节点(curr和next)都不能为null;
ListNode* swapPairs(ListNode* head) {
    if (!head || !head->next) 
        return head;
    ListNode* dummy = new ListNode();
    dummy->next = head;
    ListNode* prev = dummy;
    ListNode* curr = dummy->next;
    ListNode* next = curr->next;
    
    while (true) {
        // exchange
        prev->next = next;
        curr->next = next->next;
        next->next = curr;
        
        prev = curr;
        curr = prev->next;
        // terminal condition
        if (!curr)
            break;
        if (!curr->next)
            break;
        next = curr->next;
    }
    return dummy->next;
}

Leetecode 25

25. Reverse Nodes in k-Group

Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.
k is a positive integer and is less than or equal to the length of the linked list. If the number of nodes is not a multiple of k then left-out nodes, in the end, should remain as it is.
Follow up:
Could you solve the problem in O(1) extra memory space?
You may not alter the values in the list’s nodes, only nodes itself may be changed.
Example 1:
Input: head = [1,2,3,4,5], k = 2
Output: [2,1,4,3,5]
Example 2:
Input: head = [1,2,3,4,5], k = 3
Output: [3,2,1,4,5]
Example 3:
Input: head = [1,2,3,4,5], k = 1
Output: [1,2,3,4,5]
Example 4:
Input: head = [1], k = 1
Output: [1]

  • 思路:
    总体还是通过链表的轮转方法,注意进行反转的前提条件。
  1. 首先检测是否满足反转的前提条件,待反转的节点不为空(也是反转结束的条件),通过设置一个check指针来判断;
  2. 使用连边的轮转方法,轮转k-1次,也就实现了k个节点的反转;
  3. 将prev指针向前移动至start,然后循环进行判断和k-1次轮转;
ListNode* reverseKGroup(ListNode* head, int k) {
    if (!head || !head->next || k==1)
        return head;
    ListNode* dummy = new ListNode();
    dummy->next = head;
    ListNode* prev = dummy;
    ListNode* start = nullptr;
    ListNode* next = nullptr;
    ListNode* check = nullptr;
    
    while (true) {
        // check for reverse
        check = prev;
        for (int i = 0; i < k; ++i) {
            if (!check->next)
                return dummy->next;
            check = check->next;
        }
        
        start = prev->next;
        next = start->next;
        // reverse
        for (int i = 0; i < (k - 1); ++i) {
            start->next = next->next;
            next->next = prev->next;
            prev->next = next;
            // next rotate
            next = start->next;
        }
        // next group
        prev = start;
    }
    return dummy->next;
}

Leetecode 147

147. Insertion Sort List

Sort a linked list using insertion sort.
Algorithm of Insertion Sort:
(1) Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list.
(2) At each iteration, insertion sort removes one element from the input data, finds the location it belongs within the sorted list, and inserts it there.
(3) It repeats until no input elements remain.

  • 思路:
  1. 定义一个新列表,并使用一个虚拟节点dummy指向该列表,初始为nullptr;
  2. 使用insert指针指向head列表中待插入的节点,并将该节点从head列表中取出成独立节点;
  3. 使用start指针从dummy开始向后遍历结果列表,比较start->next和insert,当发现比insert节点值大时,将insert节点插入到start和start->next节点之间;
  4. 当遍历结束时,如果插入条件始终不满足,那么将insert节点作为结果列表最后一个节点进行插入;
ListNode* insertionSortList(ListNode* head) {
    if (!head || !head->next)
        return head;
    ListNode* dummy = new ListNode(INT_MIN);
    dummy->next = nullptr;
    ListNode* start = dummy;   
    ListNode* insert = head;
    
    while (insert) {
        // 从dummy重新遍历结果列表
        start = dummy;
        // 将insert节点从head列表中取出,作为一个单独节点
        head = head->next;
        insert->next = nullptr;
        while (start->next) {
            if (start->next->val > insert->val) { // 插入条件3
                insert->next = start->next;
                start->next = insert;
                break;
            } else {
                start = start->next;
            }
        }
        if (!start->next) { // 插入条件4
            insert->next = start->next;
            start->next = insert;
        }
        res;
    }
    return dummy->next;  
}

Leetecode 148

148. Sort List

Given the head of a linked list, return the list after sorting it in ascending order.
Follow up: Can you sort the linked list in O(n logn) time and O(1) memory (i.e. constant space)?

  • 思路:
    使用链表的归并排序算法,额外使用一个节点。
  1. 将一个列表分割为两个,使用快慢指针方法;
  2. 实现将两个列表从小到大排序,merge为一个列表;
  3. 递归使用
// 排序归并
ListNode* mergeList(ListNode* l1, ListNode* l2) {
    ListNode* l = new ListNode();
    ListNode* start = l;
    while (l1 && l2) {
        if (l1->val < l2->val) {
            start->next = l1;
            l1 = l1->next;
        } else {
            start->next = l2;
            l2 = l2->next;
        }
        start = start->next;
    }
    if (l1)
        start->next = l1;
    if (l2)
        start->next = l2;
    ListNode* res = l->next;
    delete l;
    return res;
}
// 分割列表为两部分
ListNode* sortList(ListNode* head) {
    if (!head || !head->next)
        return head;
    // 使用快慢指针来获取列表中间位置节点
    ListNode* fast = head;
    ListNode* slow = head;
    // find mid list
    while (fast->next && fast->next->next) {
        slow = slow->next;
        fast = fast->next->next;
    }
    ListNode* right = slow->next;
    slow->next = nullptr;// 将列表分为两个列表
    // 递归
    ListNode* l1 = sortList(head);
    ListNode* l2 = sortList(right);
    return mergeList(l1, l2);
}

Leetecode 237

237. Delete Node in a Linked List

Write a function to delete a node in a singly-linked list. You will not be given access to the head of the list, instead you will be given access to the node to be deleted directly.
It is guaranteed that the node to be deleted is not a tail node in the list.
Example 1:
Input: head = [4,5,1,9], node = 5
Output: [4,1,9]
Explanation: You are given the second node with value 5, the linked list should become 4 -> 1 -> 9 after calling your function.

  • 思路:
    直接删除指定的链表中的节点,方法时将下一个节点复制到待删除的节点,然后删除下一个节点。
    注意:该删除方法无法删除链表的最后一个节点!!
void deleteNode(ListNode* node) {
    if (!node)
        return;
    if (!node->next) {
        delete node;
        node = nullptr;
    }
    ListNode* del = node->next;
    node->val = del->val;
    node->next = del->next;
    delete del;
}

Leetecode 19

19. Remove Nth Node From End of List

Given the head of a linked list, remove the nth node from the end of the list and return its head.
Follow up: Could you do this in one pass?
Example 1:
Input: head = [1,2,3,4,5], n = 2
Output: [1,2,3,5]

  • 思路:
  1. 首先构造出两个节点start和end,二者之间的间距n个节点;
  2. 同时移动两个节点,直到end指向列表末尾,此时start指向倒数第n个节点;
  3. 删除start节点即可。
ListNode* removeNthFromEnd(ListNode* head, int n) {
    ListNode* dummy = new ListNode();
    dummy->next = head;
    ListNode* prev = dummy;
    ListNode* start = head;
    ListNode* end = start;
    // 拉开start和end之间的距离满足n个节点
    for (int i = 0; i < n - 1; ++i) {
        if (!end->next)
            throw runtime_error("length of list less than n!\n");
        end = end->next;
    }
    // start和end同时向后移动,直到end达到列表末尾
    while (end->next) {
        prev = prev->next;
        start = start->next;
        end = end->next;
    }
    // 输出start节点(倒数第n个节点)
    prev->next = start->next;
    delete start; 
     
    return dummy->next;;
}

Leetecode 61

61. Rotate List

Given the head of a linked list, rotate the list to the right by k places.
Example 1:
Input: head = [1,2,3,4,5], k = 2
Output: [4,5,1,2,3]
Example 2:
Input: head = [0,1,2], k = 4
Output: [2,0,1]

  • 思路:
  1. 获得链表的长度count,并获取一个指向最后一个节点的指针start
  2. 计算实际转动的次数: k = count - k % count
  3. 将链表转换为一个环(start->next = head)
  4. 通过start指针向前移动k次,得到prev指针
  5. 返回prev->next作为头指针
ListNode* rotateRight(ListNode* head, int k) {
    if (!head || !head->next)
        return head;
    
    int count = 1;
    ListNode* start = head;
    while(start->next) {
        start = start->next;
        count++;
    }
    // make a circle
    start->next = head;
    // move prev pointer
    k = count - (k % count);
    ListNode* prev = start;
    for (int i = 0; i < k; ++i) {
        prev = prev->next;
    }
    ListNode* ret = prev->next;
    prev->next = nullptr;
    
    return ret;
}

Leetecode 143

143. Reorder List

Given a singly linked list L: L0→L1→…→Ln-1→Ln,
reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…
You may not modify the values in the list’s nodes, only nodes itself may be changed.
Example 1:
Given 1->2->3->4, reorder it to 1->4->2->3.
Example 2:
Given 1->2->3->4->5, reorder it to 1->5->2->4->3.

  • 思路
  1. 寻找中间节点(快慢指针),将列表分割为两个列表
  2. 反转第二个列表
  3. 将两个列表进行merge操作
void reorderList(ListNode* head) {
   if (!head || !head->next)
       return;
   // find mid node and split into two lists
   ListNode* prev = new ListNode();
   prev->next = head;
   ListNode* mid = head;
   ListNode* end = head;
   while (true) {
       // odd number
       if (!end->next) {
           break;
       }
       // even number
       if (!end->next->next) {
           prev = prev->next;
           mid = mid->next;
           break;
       }
       // move to next
       prev = prev->next;
       mid = mid->next;
       end = end->next->next;
   }
   prev->next = nullptr; // split into two lists
   
   // reverse mid list
   ListNode* dummy = new ListNode();
   dummy->next = mid;
   ListNode* next = mid->next;
   while (next) {
       mid->next = next->next;
       next->next = dummy->next;
       dummy->next = next;
       
       next = mid->next;
   }
   mid = dummy->next;
   // merge
   ListNode* start = head;
   while (start && mid) {
       dummy->next = start;
       start = start->next;
       
       dummy->next->next = mid;
       mid = mid->next;
       
       dummy = dummy->next->next;
   }
   if (start)
       dummy->next = start;
   if (mid)
       dummy->next = mid;
}

Leetecode 234

234. Palindrome Linked List

Given a singly linked list, determine if it is a palindrome.
Example 1:
Input: 1->2
Output: false
Example 2:
Input: 1->2->2->1
Output: true

  • 思路:
  1. 找到中间节点(快慢指针)
  2. 反转第二个List
  3. 逐一对比两个List的元素是否相同
bool isPalindrome(ListNode* head) {
    if (!head || !head->next)
        return true;
    // find mid node
    ListNode* fast = head;
    ListNode* low = head;
    while (true) {
        if (!fast->next)
            break;
        if (!fast->next->next)
            break;
        low = low->next;
        fast = fast->next->next;
    }
    ListNode* mid = low->next;
    // reverse
    ListNode* dummy = new ListNode();
    dummy->next = mid;
    ListNode* next = mid->next;
    while (next) {
        mid->next = next->next;
        next->next = dummy->next;
        dummy->next = next;
        
        next = mid->next;
    }
    // compare
    mid = dummy->next;
    while (mid) {
        if (mid->val != head->val)
            return false;
        mid = mid->next;
        head = head->next;
    }
    return true;
}
开源数字人、虚拟直播部署教程 对,你无看错,是欧美的。在直播带货案例里,我们把模型导入到ue4,我们给模型在ue4里预设了四个动作(站着、站着说话、坐着、坐着说话),三个表情(平静、开发、愤怒),三个镜头(全局、近矩说话、看显示器播放商品展示)。我们只需要把目标主播的直播给录制下来,提取样本数据,然后训练一个从粉丝的不同刺激的组合,到主播的不同响应方式的多元逻辑回归的数学模型参数即可。 阅读详情

相关推荐

RTX 50系列显卡选购指南:从Stable Diffusion到深度学习,哪款最适合你的AI需求?

本文深入分析了RTX 50系列显卡如何满足不同的AI应用需求。针对Stable Diffusion图像生成,强调显存容量是关键;对于大语言模型本地推理,需平衡算力与显存;而深度学习训练则更看重算力效率。文章对比了RTX 5090、5080、5070等型号的核心规格与适用场景,并提供了从入门到专业的实战配置建议,帮助用户根据自身AI工作负载精准选择最具性价比的显卡。

linux6sysadmin的博客 692

Leetcode刷题--链表(C++)

数据结构介绍: 1 链表由节点和指针构成;2 无法直接获取任意节点的值,必须通过指针;3 插入删除比较方便;4 很多链表问题可以用递归来解决;5 未遍历到尾指针时,无法确定链表长度。 leetcode默认链表表示方法: struct ListNode { int val; ListNode *next; ListNode(int x) : val(x),next(nullptr) {} }; 注意:在链表操作时,特别是删除节点,会因为当前节点进行操作而导致...

qq_27348093的博客 504

高通 Gen AI 推理扩展 (GENIE)(5):实战指南与Engine API深度解析

本文深入解析高通Gen AI推理扩展(GENIE)的Engine API核心功能与实战应用,涵盖引擎实例化、多引擎动态切换、性能调优及跨平台部署等关键技巧。通过详细代码示例和性能数据,帮助开发者高效利用GENIE进行AI推理,提升应用性能与稳定性。

weixin_29065959的博客 465

LeetCode刷题(C++)-链表篇

《代码随想录》第二章-链表

qq_53212979的博客 421

Amesim与Simulink联合仿真:S-Function接口配置与实战避坑指南

本文详细介绍了Amesim与Simulink联合仿真中S-Function接口的配置方法与实战避坑指南。从环境搭建、编译器配置到S-Function接口实战,逐步解析关键步骤与常见问题解决方案,帮助工程师高效实现多领域系统仿真,特别适合汽车、航空航天等复杂系统建模场景。

weixin_29173777的博客 344

电蚊拍为什么能秒杀蚊子?深入解析两种四倍压整流电路设计差异

本文深入解析电蚊拍秒杀蚊子的核心原理——四倍压整流电路设计,对比对称式与级联式两种方案的性能差异。通过详细电路分析、实测数据对比和选型建议,揭示高压电路设计的关键技术要点,为电子爱好者和工程师提供实用参考。

rust6ferris的博客 752

Leetcode链表篇总结(C++)

文章目录一、基础知识二、经典题目1、 203:移除链表元素 一、基础知识 1、链表的定义 单链表:(leetcode上的实现) * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * ListNode(int x) : val(x), next(nullptr) {}

weixin_42783170的博客 3933

相机标定-张正友棋盘格标定法

(X,Y,Z)为在世界坐标系下一点的物理坐标 ( u , v ) 为该点对应的在像素坐标系下的像素坐标 引入齐次坐标的原因:引入齐次坐标的目的是为了升维,将坐标从二维坐标变为三维坐标。 2.相机成像过程 相机成像系统中,共包含四个坐标系:世界坐标系、相机坐标系、图像坐标系、像素坐标系。 (1)世界坐标系(,,) 描述目标在真实世界中的位置引入的参考坐标系。 (2)相机坐标系(,,) ...

qq_41275123的博客 1万+

C++链表基本用法及LeetCode经典链表题目汇总

链表基本用法: 目录 链表基本用法: C++链表及基本操作 LeetCode链表经典题目汇总: 2. 两数相加 19. 删除链表的倒数第 N 个结点 21. 合并两个有序链表 23. 合并K个升序链表 24. 两两交换链表中的节点 25. K 个一组翻转链表 61. 旋转链表 92. 反转链表 II 141. 环形链表 142. 环形链表 II 160. 相交链表 328. 奇偶链表 C++链表及基本操作 1 2 ...

whocare的博客 4147

“守望先锋”网络同步分析

守望先锋”(Overwatch)是一款由暴雪娱乐开发的团队基础第一人称射击游戏(FPS),于2016年正式发布。游戏以其独特的角色设计、丰富的游戏模式和高度的团队合作性而受到广泛欢迎。类型:第一人称射击(FPS)/多人在线战斗竞技场(MOBA元素)平台玩家人数:每场比赛由两个六人队伍组成,共12名玩家。客户端/服务器模型:在这种模型中,客户端负责处理用户输入和表现逻辑,而服务器则负责游戏的核心逻辑和状态管理。客户端与服务器之间通过网络进行通信,确保游戏状态的一致性。强同步机制。

本博客聚焦游戏开发技巧、创业实战心得及大学热门课程干货。这里既有技术深度,也有思维广度,无论你是开发者、创业者还是高校学子,都能在这里找到适合自己的成长之路! 428

FreeRTOS系统从入门到精通万字保姆级教程

例如,在基于ARM的硬件平台上,可能需要实现针对ARM处理器的上下文切换代码,并确保FreeRTOS能够正确地响应和处理ARM架构的中断。需要注意的是,在删除任务之前应确保任务已经完成了其所有重要的工作,并且没有其他的任务依赖于它,以避免数据丢失或系统不稳定。任务的优先级设定是其中的关键环节。在复杂的系统中,可能会有大量的任务需要同时运行,而这些任务的重要性和紧急程度各不相同。这通常包括创建初始任务(这些任务将负责系统的初始化和后续任务的调度)、设置系统时钟(以确保任务的准时调度和延时功能的正确性)等。

大模型大数据攻城狮的专栏 2070

【Leetcode】链表 简单题大全 c++

经典简单链表题总结

mie haha 798

时间序列分析(Time Series Analysis) 原理与代码实例讲解

时间序列分析(Time Series Analysis) - 原理与代码实例讲解 作者:禅与计算机程序设计艺术 / Zen and the Art of Computer Programming 关键词:时间序列预测,ARIMA模型,状态空间模型,SARIMA模型,机器学习

AI天才研究院 1248

题解 力扣 LeetCode 206 反转链表 C/C++ 三种思路

可以用迭代和递归来做,每种又可以具体写成不同样子,这里给出三种不同思路的代码 先说迭代: 遍历整个链表 第一个节点是将来的最后一个节点,令它指向 NULL 之后的每个节点指向之前的节点即可,每次反转前都要记录一下下一个节点 否则会和之后的节点断开联系 former 用来记录之前的节点 latter 用来在该次反转前记录下一个节点 p 不为 NULL 就继续执行,结束执行后返回 p 循环体上半部分结束后判断 latter,因为我们要返回 p 作为最后一个节点的地址 所以不能让 p == NULL

qwq_ovo_pwp的博客 2347

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

【力扣(LeetCode)】【C/C++】【203.移除链表元素】

力扣(LeetCode)

繁华倾夏的博客 262

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

题解 力扣 LeetCode 61 旋转链表 C/C++

时间复杂度 O(N) 1.特殊情况判断:head == NULL 2.获取链表长度 length,该数据很有用,等下会用到好几次 3.k %= length,防止 k过大出现多轮重复操作 4.找到将来的末节点和头结点,记录将来的头结点后,将来的末节点->next = NULL 举个例子: {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, NULL} rotate 3 >> {8, 9, 10, 1, 2, 3, 4, 5, 6, 7, NULL} 7 是将来的末节点,8 是将来的头结点

qwq_ovo_pwp的博客 543

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

LeetCode力扣--203题:移除链表元素C++

题目描述: LeetCode203:移除链表元素 要求:删除链表中等于给定值 val 的所有节点。 示例: 输入: 1->2->6->3->4->5->6, val = 6 输出: 1->2->3->4->5 解法: 废话不多说,先来一段官方的代码与原创代码对比截图: 官方代码: 官方代码不美观在: 0:一共15行代码,代码缩进结构十分紧凑 1:在堆上申请了一块内存,最后还得释放 2:在栈区创建了5个指针变量,操作繁琐 3:在while循环结束之

BShanj的博客 619

【力扣(LeetCode)】【C/C++】【234.回文链表】

力扣(LeetCode)

繁华倾夏的博客 111

指定区间的链表反转问题|力扣leetcode92反转链表2(cpp、Java实现)

反转指定区间链表可以使用以下四种方法:头插法是一种利用辅助节点将每个节点插入到链表头部的方法。具体来说,我们先创建一个辅助节点,然后依次遍历链表中的每个节点,将其插入到辅助节点的后面,随后将辅助节点指向该节点。最后,我们将辅助节点后面的节点全部取出来,即为反转后的链表。该方法的时间复杂度为O(n),空间复杂度为O(1)。这种方法思路简单,代码实现也直接。以链表的指针作为遍历的方式,依次反转指定区间内的节点。每遍历到一个节点就将其反转,直到遍历完指定区间内的所有节点。

染落林间色的博客 3018

【力扣(LeetCode)】【C/C++】【141.环形链表】

力扣(LeetCode)

繁华倾夏的博客 153

《力扣》链表 | 234. 回文链表 C++题解

思路简单,找到链表的中点,然后将中点之后的进行反转,并将反转的链作为一个新链表,然后新链表和原链表从头开始比较判断即可。做这一题先可以做876和206两个题目。

2302_76695233的博客 252

Leetcode 力扣hot100 ——K 个一组翻转链表C++题解

基于C++的K 个一组翻转链表题解,空间复杂度o(1)。

qq_44880368的博客 1073

力扣(LeetCode)-学习-链表-设计链表-C++通过代码

题目来源: 链表学习 题目描述: 设计链表的实现。您可以选择使用单链表或双链表。单链表中的节点应该具有两个属性:val 和 next。val 是当前节点的值,next 是指向下一个节点的指针/引用。如果要使用双向链表,则还需要一个属性 prev 以指示链表中的上一个节点。假设链表中的所有节点都是 0-index 的。 在链表类中实现这些功能: get(index):获取链表中第 index 个节点的值。如果索引无效,则返回-1。 addAtHead(val):在链表的第一个元素之前添加一个值为 val 的

garbage_man的博客 498

力扣160链表相交(c++版)

如果两个链表相交,又都不存在环,那么不难想象这两个链表共同构成了一个Y型,相交部分全部都相同,两链表交点处指针相等。此时我们就可以比较指针A和指针B是否相同,如果不相同,俩指针同时向后移动1个next,如果相同,则找到交点。声明指针A指向链表A的头结点,指针B指向链表B的头结点。我们求出两个链表的长度,并求出两个链表长度的差值gap。让两个链表末尾对齐,指向长链表的指针移动gap个位置。否则循环退出返回空指针。时间复杂度度O(n+m)

qq_51560134的博客 733

《力扣》链表 | 19. 删除链表的倒数第 N 个结点 C++题解

2.然后a,b一起移动,当a移动到末尾的时候,b就恰好移动到倒数第n个数。也就是我们通过a指针限制b只能移动(len-n)个节点(带头节点)给你一个链表,删除链表的倒数第。好神奇的解法,有股相对运动的赶脚。双指针:a,b(同时指向头节点)个结点,并且返回链表的头结点。1.先让a指针移动n个节点。

2302_76695233的博客 689

【力扣(LeetCode)】【C/C++】【206.反转链表】

力扣(LeetCode)

繁华倾夏的博客 218
上一篇: C++常用方法记录
下一篇: Leetcode C++ 队列
mathnan
博客等级 码龄18年 1粉丝 15原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值