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. 字符串的长度超过了为 maxJsonLength 属性设置的值

    当出现类似标题的错误时,可以按照如下方法解决: 1. 检查是否传递的JSON字符串长度过长 2.增加JSON串的长度设置,设置如下: <system.web.extensions>     ...

  2. CocosBuilder 多分辨率基础

    最近两个项目大量使用了CocosBuilder, 对于开发效率提高是巨大的. 一直计划写一篇博客谈谈CocosBuilder的多分辨率问题, 懒病加上一些疙疙瘩瘩的小事情, 拖延了一个多月, 才终于下 ...

  3. Canvas贝塞尔二级曲线

    当前点到控制点,控制点到末尾点的两个连线,与这两个连线相切:<!DOCTYPE html> <html lang="en"> <head> &l ...

  4. svn git协同管理

    项目开发过程中总有一些奇奇怪怪的需求出现. 我们的项目管理是使用SVN的,用SVN是历史原因,无法整个项目向Git切换.由于我需要管理SVN,做一些代码合并工作.每次合并都会遇到SVN代码需要对比查看 ...

  5. MIPS 跳转指令BAL vs JAL

    今天调试程序,发现在windows和Linux下,diab编译的结果不一样,一个能跑一个不能跑.最后定位到了函数跳转上. 程序代码里的函数跳转写的是BAL,在windows下编译结果正常,在Linux ...

  6. Awesome Chrome 插件集锦

    子曾曰:"工欲善其事,必先利其器.居是邦也."--语出<论语·卫灵公>:其后一百多年,荀子也在其<劝学>中倡言道:"吾尝终日而思矣,不如须臾之所学 ...

  7. web开发的性能准则(减少页面加载时间方面)

    准则(概述) 减少 HTTP 请求 使用CDN加速 避免空的src或href属性值 增加过期头 启GZIP压缩 把css文件放到头部 把javascript放到尾部 避免使用css表达式 删除不使用的 ...

  8. 地图学与GIS制图的基础理论(一)

    说到地图制作,很多人第一时间就会跟地图学进行挂钩.是的,地图学的很多理论和知道思想都非常适合基于GIS制图.可以说,利用GIS进行电子地图制作,其实也属于地图学的一小部分. 地图学是研究地图的理论.地 ...

  9. C#读取XML方式

    前言 前一篇我们简单给大家做了XML的介绍,现在咱们继续这个系列 XML文件是一种常用的文件格式,例如WinForm里面的app.config以及Web程序中的web.config文件,还有许多重要的 ...

  10. Java线程中yield()的用法

    Thread.yield()方法的作用:暂停当前正在执行的线程,并执行其他线程.(可能没有效果) yield()让当前正在运行的线程回到可运行状态,以允许具有相同优先级的其他线程获得运行的机会.因此, ...