`

237. Delete Node in a Linked List

阅读更多

237. Delete Node in a Linked List

Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.

Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value 3, the linked list should become 1 -> 2 -> 4after calling your function.

java实现--方法没有给出头结点,只能将本结点的下一结点的值赋值给该结点,然后删除下一结点

刚开始没想明白。。。

/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int x) { val = x; }
 * }
 */
public class Solution {
    public void deleteNode(ListNode node) {
        if(node!=null){
            node.val=node.next.val;
            node.next=node.next.next;
        
           
        }
        
    }
}

 

分享到:
评论

相关推荐

    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不会-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 ...

    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]...

    微软内部资料-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