[LeetCode]237. Delete Node in a Linked List
来源:互联网 发布:java 垃圾回收 手动 编辑:程序博客网 时间:2024/06/08 07:04
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.
我的解法:同I copied every node.val to the one before and set the last one to null. What a shame.
/** * 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) { while(node.next.next!=null){ node.val=node.next.val; node=node.next; } node.val=node.next.val; node.next=null; }}
public void deleteNode(ListNode node) { node.val = node.next.val; node.next = node.next.next;}
阅读全文
0 0
- leetcode: Delete Node in a Linked List
- LeetCode Delete Node in a Linked List
- 【leetcode】Delete Node in a Linked List
- Leetcode: Delete Node in a Linked List
- [LeetCode]Delete Node in a Linked List
- 【leetcode】Delete Node in a Linked List
- Leetcode Delete Node in a Linked List
- LeetCode || Delete Node in a Linked List
- [LeetCode] Delete Node in a Linked List
- LeetCode-Delete Node in a Linked List
- 【leetCode】Delete Node In A Linked List
- [leetcode] Delete Node in a Linked List
- [LeetCode]Delete Node in a Linked List
- [leetcode]Delete Node in a Linked List
- Leetcode: Delete Node in a Linked List
- LeetCode Delete Node in a Linked List
- LeetCode-Delete Node in a Linked List
- leetcode | Delete Node in a Linked List
- svn 服务器端和客户端配置方法
- Monthly Expense(二分法)
- python uiautomator API
- 0-1背包问题练习
- SpringCloud分布式开发五大神兽
- [LeetCode]237. Delete Node in a Linked List
- @SpringBootApplication注解
- echarts ajax请求方式
- wp-postviews文章浏览次数与点击排行详解
- msiexec.exe进程在安装sqlserver 2012 sp1后继续运行,增加到约100%CPU
- Leetcode 442. Find All Duplicates in an Array
- 关于js模糊匹配
- linux的poll机制
- js生成随机数(数字+字母)