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

Write a function to delete a node (except the tail) in a singly linked list, given only access to th...
  • sunao2002002
  • sunao2002002
  • 2015年07月27日 13:54
  • 5171

leetcode 237: Delete Node in a Linked List

leetcode 237: Delete Node in a Linked List PYTHON JAVA C++
  • xudli
  • xudli
  • 2015年07月15日 14:50
  • 16995

237. Delete Node in a Linked List [easy] (Python)

题目链接https://leetcode.com/problems/delete-node-in-a-linked-list/题目原文 Write a function to delete a n...
  • coder_orz
  • coder_orz
  • 2016年05月13日 21:18
  • 1401

LeetCode(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 ...
  • fly_yr
  • fly_yr
  • 2015年08月15日 21:32
  • 1041

Leetcode_237_Delete Node in a Linked List

本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/47334649 Write a function t...
  • pistolove
  • pistolove
  • 2015年08月07日 09:53
  • 1295

leetcode笔记--Delete Node in a Linked List

题目:难度(Easy) Write a function to delete a node (except the tail) in a singly linked list, given only...
  • u010366748
  • u010366748
  • 2016年02月19日 14:36
  • 239

leetcode237~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 th...
  • stone_yw
  • stone_yw
  • 2017年03月25日 08:26
  • 231

leetcode237 Delete Node in a Linked List

237. Delete Node in a Linked List Total Accepted: 66681 Total Submissions: 152654 Diffi...
  • qq_31186409
  • qq_31186409
  • 2016年03月05日 11:06
  • 121

[LeetCode237]Delete Node in a Linked List

题目来源:https://leetcode.com/problems/delete-node-in-a-linked-list/ Write a function to delete a n...
  • hnxijie
  • hnxijie
  • 2015年11月12日 15:33
  • 102

Delete Node in a Linked List Java LeetCode

Write a function to delete a node (except the tail) in a singly linked list, given only access to th...
  • zuoyexingchennn
  • zuoyexingchennn
  • 2015年07月31日 12:21
  • 900
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:LeetCode237:Delete Node in a Linked List
举报原因:
原因补充:

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