Delete a node, only give access to that node.
来源:互联网 发布:多开分身软件 编辑:程序博客网 时间:2024/05/19 19:16
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.
思路:Only access to that node, we can copy the value of next node to that node, and point to the next.next;
/** * 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.next == null) { return; } ListNode next = node.next; node.val = next.val; node.next = next.next; return; }}
0 0
- Delete a node, only give access to that node.
- Q.2.3 Implement an algorithm to delete a node in the middle of a single linked list, given only acce
- Delete Node in a BST
- Delete Node in a BST
- Delete Node in a BST
- Delete Node In A LinkedList
- tree下subtree.node NotImplementedError: Use label() to access a node label.报错
- define a class for a linked list and write a method to delete the nth node.
- There is only one kind of failure,that is to give up halfway.
- C++: delete a node from linked list
- C++ delete a node from BST
- leetcode: Delete Node in a Linked List
- LeetCode Delete Node in a Linked List
- Delete Node in a Linked List
- 【leetcode】Delete Node in a Linked List
- Delete Node in a Linked List
- Delete Node in a Linked List
- Leetcode: Delete Node in a Linked List
- CVE-2013-5211漏洞整改方法
- 统计单词个数 状态机方法
- 我的Unity3D学习日记-04(Transform,Time,Mathf类以及动态在场景中生成Prefab)
- mysql从csv文件导入数据时提示int类型出现' '(空字符串)
- 栈实现的带括号的计算器
- Delete a node, only give access to that node.
- js 识别or 手机
- Kali进行web渗透笔记(一)
- MJExtension 框架的使用
- Python数字
- PHP图片上传时$_FILES为空解决
- Microsoft Windows远程桌面协议中间人攻击漏洞(CVE-2005-1794)解决方案
- CALayer学习
- Android通过ViewPager实现Tab面板实例