LeetCode237:Delete Node in a Linked List

原创 2015年11月17日 17:15:57

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 -> 4 after calling your function.

 

/**
 * 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)
            return;
        if(node.next==null)
            node=null;
        node.val=node.next.val;
        node.next=node.next.next;
    }
}




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

相关文章推荐

leetCode 237. Delete Node in a Linked List

题目链接:https://leetcode.com/problems/delete-node-in-a-linked-list/     题目内容: Write a function to del...

【一天一道LeetCode】#237. Delete Node in a Linked List

一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder‘s Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目...

LeetCode之路:237. Delete Node in a Linked List

LeetCode之路:237. Delete Node in a Linked List 一、引言这道题 哈哈哈 这是我做完了之后看到最高票答案的标题,顿时觉得有些滑稽:)那么接下来就让我们看看这...

【LeetCode】 Delete Node in a Linked List

Delete Node in a Linked List  Total Accepted: 1872 Total Submissions: 3662 Write a...

开荒新系列之Leetcode: 003-Delete Node in a Linked List

开荒Leetcode: NO.003 Delete Node in a Linked List最近晚上决定睡得比较早,于是更新就慢下来了。DFS和BFS还有递归写法,速度更快一些,留坑待填。题目大意:...

LeetCode---Delete Node in a Linked List

题目大意:给出一个链表中的节点,在链表中删除该节点,如果是尾节点则不删除。如:链表 1 -> 2 -> 3 -> 4 要删除链表中值为3的节点,则操作后的链表为1 -> 2 -> 4。 算法思想: ...

LeetCode------Delete Node in a Linked List

题目简介 Write a function to delete a node (except the tail) in a singly linked list, given onl...

Leetcode -Delete Node in a Linked List !

多坚持了一天。多亏今天还有一道easy的题。。 一、分析这题就是说: 删除一个单向链表的某个节点,但是只给你要删的这个节点,没有头结点。一看这题,给人第一个感觉估计就是没头绪,这单向链表,你...

LeetCode从零单排之零分段——Delete Node in a Linked List(删除链表中的元素)

原题: Write a function to delete a node (except the tail) in a singly linked list, given only acc...

leetcode- Delete Node in a Linked List&Remove Linked List Elements

Problem: Delete Note in a LinkedList & Remove LinkedList Elements
  • aaasy
  • aaasy
  • 2016-04-09 17:05
  • 54
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)