/** * Definition for singly-linked list. * public class ListNode { * public int val; * public ListNode next; * public ListNode(int x) { val = x; } * } */ public class Solution { public void DeleteNode(ListNode node) { node.val = node.next.val; node.next = node.next.next; } }
https://leetcode.com/problems/delete-node-in-a-linked-list/#/description
python的代码:
1 class Solution: 2 def deleteNode(self, node): 3 """ 4 :type node: ListNode 5 :rtype: void Do not return anything, modify node in-place instead. 6 """ 7 node.val = node.next.val 8 node.next = node.next.next