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

本文共 1182 字,大约阅读时间需要 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.

代码:

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

  

转载于:https://www.cnblogs.com/zlrrrr/p/10058359.html

你可能感兴趣的文章
bzoj2038 [2009国家集训队]小Z的袜子(hose)
查看>>
Postman-----如何导入和导出
查看>>
【Linux】ping命令详解
查看>>
8、RDD持久化
查看>>
第二次团队冲刺--2
查看>>
使用Xshell密钥认证机制远程登录Linux
查看>>
【模板】最小生成树
查看>>
java面试题
查看>>
pair的例子
查看>>
uva 387 A Puzzling Problem (回溯)
查看>>
Oracle中包的创建
查看>>
django高级应用(分页功能)
查看>>
【转】Linux之printf命令
查看>>
关于PHP会话:session和cookie
查看>>
C#double转化成字符串 保留小数位数, 不以科学计数法的形式出现。
查看>>
利用IP地址查询接口来查询IP归属地
查看>>
构造者模式
查看>>
Hbuild在线云ios打包失败,提示BuildConfigure Failed 31013 App Store 图标 未找到 解决方法...
查看>>
找到树中指定id的所有父节点
查看>>
jQuery on(),live(),trigger()
查看>>