`
songlj
  • 浏览: 15923 次
社区版块
存档分类
最新评论

Delete Node in a Linked List

阅读更多

解题思路:指定删除任一节点,因无头节点指针,实际删除节点即是删除节点的值,所以可以将要删除节点和后继节点的值替换,删除后继节点即可。

Java代码实现:

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
void deleteNode(struct ListNode* node) {
    struct ListNode *p,*q;
    p=q=node;
    q=p->next;
    p->val=q->val;
    p->next=q->next;
    free(q);
}
原地地址:https://leetcode.com/problems/delete-node-in-a-linked-list/




版权声明:本文为博主原创文章,未经博主允许不得转载。

分享到:
评论

相关推荐

    apachecn#Interview#delete_node_in_a_linked_list问题1

    Delete Node in a Linked List问题This is a LeetCode question, I knew its solution,

    Leetcode的ac是什么意思-LeetCodeInJava:leetcode-java

    Leetcode的ac是什么...Delete Node in a Linked List #238 Product of Array Except Self #242 Valid Anagram #258 Add Digits #260 Single Number III #274 H-Index #283 Move Zeroes #292 Nim Game #318 Maximum P

    LeetCode最全代码

    * [Linked List](https://github.com/kamyu104/LeetCode#linked-list) * [Stack](https://github.com/kamyu104/LeetCode#stack) * [Queue](https://github.com/kamyu104/LeetCode#queue) * [Heap]...

    leetcode不会-delete-node-in-a-linked-list:删除链表中的节点

    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. Example 2: Input: head = [4,5,1,9], node = 1 ...

    微软内部资料-SQL性能优化5

    The data pages in the table are kept in a doubly linked list called the page chain. The order of pages in the page chain, and the order of rows on the data pages, is the order of the index key or ...

    BobBuilder_app

    Splitting a page when full is simple and does not require a tree traversal for node overflow checking as in a b+tree. Main page list updates are infrequent and hence the locking of the main page list...

    微软内部资料-SQL性能优化3

    For example, a second transaction traversing the doubly linked list mentioned above would see the list before or after the insert, but it will see only complete changes. Durability After a ...

    leetcode中国-leetcode-experience:zpxuleetcode体验

    (delete-node-in-a-linked-list) 182: 查找重复的电子邮箱(duplicate-emails) 2019/12/3 1221. 分割平衡字符串 (split-a-string-in-balanced-strings) 595. 大的国家 (big-countries) 1021. 删除最外层的括号 ...

    project-code-py:适用于Python问题的GPT-2模型

    项目代码py 适用于Python问题的GPT-2模型 ... 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 nod

    《数据结构 1800题》

    THEN A[j]与A[j+1]对换; 其中 n为正整数,则最后一行的语句频度在最坏情况下是(D ) 郴州都市网 www.0735.cc郴州人才网 www.CZHR.com www.989.org 《数据结构 1800题》 A. O(n) B. O(nlogn) C. O(n3)...

    py-lru:从头开始的LRUCache的python实现

    delete_node 删除双向链接列表中的节点。 delete 删除该值在双链表中的第一个匹配项。 LRU缓存 LRU缓存的API如下: 姓名 描述 __setitem__ 针对缓存中提供的键设置提供的值。 __getitem__ 获取针对提供的键...

Global site tag (gtag.js) - Google Analytics