leetcode 237: Delete Node in a Linked List
生活随笔
收集整理的這篇文章主要介紹了
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 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.?
編碼:
1 /** 2 * Definition for singly-linked list. 3 * public class ListNode { 4 * int val; 5 * ListNode next; 6 * ListNode(int x) { val = x; } 7 * } 8 */ 9 public class Solution { 10 public void deleteNode(ListNode node) { 11 node.val = node.next.val; 12 node.next = node.next.next; 13 } 14 }
?
?
轉載于:https://www.cnblogs.com/cactus1504/p/4807524.html
總結
以上是生活随笔為你收集整理的leetcode 237: Delete Node in a Linked List的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 黄山风景区微信公众号
- 下一篇: JavaScript sync and