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.

Subscribe to see which companies asked this question

Show Tags
Show Similar Problems
 
一上来就感觉这个题没法做啊,没有提供头结点,只是被删除的节点,怎么找到被删除节点的上一个节点啊。
看了下其他人的答案,才发现自己已经形成了思维定势。
也可以采用节点内赋值的方法
void deleteNode(ListNode* node) {
if (node == nullptr)
return;
node->val = node->next->val;
node->next = node->next->next;
}

Delete Node in a Linked List leetcode的更多相关文章

  1. [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 th ...

  2. 【LeetCode】237 & 203 - Delete Node in a Linked List & Remove Linked List Elements

    237 - Delete Node in a Linked List Write a function to delete a node (except the tail) in a singly l ...

  3. LeetCode Javascript实现 283. Move Zeroes 349. Intersection of Two Arrays 237. Delete Node in a Linked List

    283. Move Zeroes var moveZeroes = function(nums) { var num1=0,num2=1; while(num1!=num2){ nums.forEac ...

  4. [CareerCup] 2.3 Delete Node in a Linked List 删除链表的节点

    2.3 Implement an algorithm to delete a node in the middle of a singly linked list, given only access ...

  5. LeetCode_237. Delete Node in a Linked List

    237. Delete Node in a Linked List Easy Write a function to delete a node (except the tail) in a sing ...

  6. 【4_237】Delete Node in a Linked List

    Delete Node in a Linked List Total Accepted: 48121 Total Submissions: 109297 Difficulty: Easy Write ...

  7. Leetcode-237 Delete Node in a Linked List

    #237.    Delete Node in a Linked List Write a function to delete a node (except the tail) in a singl ...

  8. 237. Delete Node in a Linked List(C++)

    237. Delete Node in a Linked Lis t Write a function to delete a node (except the tail) in a singly l ...

  9. 237. Delete Node in a Linked List【easy】

    237. Delete Node in a Linked List[easy] Write a function to delete a node (except the tail) in a sin ...

随机推荐

  1. Eclipse 打开文件所在文件夹

    右击文件 > Show In > System Explorer

  2. 在vue-cli项目中安装node-sass

    1,使用save会在package.json中自动添加. ----npm install node-sass  --save ----npm install sass-loader  --save 2 ...

  3. TForm类

    显示给用户的窗体有两种:有模式和无模式的.具体使用哪一种窗体,取决于是否希望用户能够同时与这个窗体和其他窗体交互. 1.当打开一个模式窗体后,用户无法与应用程序的其他部分交互,知道用户关闭了这个窗体. ...

  4. VAST3.0规范

    VAST3.0视频广告投放规范 Posted on 2014年2月15日 1.术语 随着视频广告行业的发展,某些术语已经得到了广泛的采用.以下定义该文档中与视频广告投放相关的一些术语: 广告荚(Ad ...

  5. 在ASP.NET MVC中使用 Bootstrap table插件

    Bootstrap table: http://bootstrap-table.wenzhixin.net.cn/zh-cn/getting-started/ 1. 控制器代码: using Syst ...

  6. Grunt + Bower—前端构建利器

    目前比较流行的WEB开发的趋势是前后端分离.前端采用重量级的Javascript框架,比如Angular,Ember等,后端采用restful API的Web Service服务,通过JSON格式进行 ...

  7. js精要之继承

    // 继承object.prototype的方法 // hasOwnProperty() //检查是否存在一个给定名字的自有属性 // propertyIsEnumerable() // 检查一个自有 ...

  8. Eclipse / Intellij Idea配置Git+Maven+Jetty开发环境

    作者:鹿丸不会多项式 出处:http://www.cnblogs.com/hechao123  转载请先与我联系. 最近公司给加配了Mac,本想着花一个小时的时间搭好开发环境,最后全部弄好却用了一上午 ...

  9. Error:Failed to open zip file. Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)

    刚开始写博客,可能有点语无伦次,请大家见谅.... 今天我们来讲讲AS出现下面图片原因的问题 同学们,刚看到这个,是不是有点小懵逼,不要怕,今天我们就来讲讲,出现这个问题的原因 今天我在AS(Andr ...

  10. JavaScript处理json格式数据

    JSON即JavaScript对象标记,是一种轻量级的数据交换格式,非常适用于服务器与JavaScript的交互.JSON是基于纯文本的数据格式. JSON是JavaScript的原生格式,可以使用J ...