博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
237. Delete Node in a Linked List - Easy
阅读量:6250 次
发布时间:2019-06-22

本文共 1172 字,大约阅读时间需要 3 分钟。

Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.

Given linked list -- head = [4,5,1,9], which looks like following:

4 -> 5 -> 1 -> 9

Example 1:

Input: head = [4,5,1,9], node = 5Output: [4,1,9]Explanation: You are given the second node with value 5, the linked list             should become 4 -> 1 -> 9 after calling your function.

Example 2:

Input: head = [4,5,1,9], node = 1Output: [4,5,9]Explanation: You are given the third node with value 1, the linked list             should become 4 -> 5 -> 9 after calling your function.

Note:

  • The linked list will have at least two elements.
  • All of the nodes' values will be unique.
  • The given node will not be the tail and it will always be a valid node of the linked list.
  • Do not return anything from your function.

 

修改node的值,再删掉node下一个节点

/** * Definition for singly-linked list. * public class ListNode { *     int val; *     ListNode next; *     ListNode(int x) { val = x; } * } */class Solution {    public void deleteNode(ListNode node) {        node.val = node.next.val;        node.next = node.next.next;    }}

 

转载于:https://www.cnblogs.com/fatttcat/p/10184309.html

你可能感兴趣的文章
Linux系统挂载ntfs分区
查看>>
10.常见数据库操作1
查看>>
JavaScript高级-定义函数(类)方法
查看>>
移动web图片高度自适应的解决方案
查看>>
API
查看>>
需求获取的前期工作(不断更新)
查看>>
10.23
查看>>
hdu5420 Victor and Proposition
查看>>
如何编写可移植的c/c++代码
查看>>
#pragma pack(n)
查看>>
IntelliJ IDEA 2018.3 升级功能介绍
查看>>
基于.NET平台常用的框架整理
查看>>
【每天一道算法题】Lucky String
查看>>
整合apache+tomcat+keepalived实现高可用tomcat集群
查看>>
计算几何-HPI
查看>>
香农熵学习+例子[转载]
查看>>
利用DE2上的WM8731D/A转换器产生正弦波
查看>>
清除EasyUi combotree下拉树的值
查看>>
手写RPC框架
查看>>
Hadoop 分片、分组与排序
查看>>