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

不容易自己写对一道题,没有查找答案~

 /**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
void deleteNode(struct ListNode* node) {
struct ListNode* p = node->next;
node->val = p->val;
if (p->next == NULL)
node->next = NULL;
else
node->next = p->next;
free(p);
}

【4_237】Delete Node in a Linked List的更多相关文章

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

  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. 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 ...

  5. [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 ...

  6. 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 ...

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

  8. 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 ...

  9. 【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 t ...

随机推荐

  1. hive和ORACLE语法对比

  2. sublime ctags

    安装 ctags: 下载ctags,复制exe到系统目录或者sublime text的目录中 sublime: 安装ctags插件 使用: 快捷键 Command Key Binding Alt Bi ...

  3. projecteuler Problem 8 Largest product in a series

    The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × 8 × 9 = ...

  4. Java之重载与覆盖

    有的时候,类的同一种功能有多种实现方式,到底采用哪种实现方式,取决于调用者给定的参数.例如我们最常用的System.out.println()能够打印出任何数据类型的数据,它有多种实现方式.运行时,J ...

  5. web.xml的首页调用struts2的action解决方法

    1,首先在struts.xml里添加如下代码:注意位置 <constant name="struts.action.extension" value="do,act ...

  6. 关于mysql和Apache以及nginx的监控脚本怎么写会比较好的记录

    最近,自己业务进行上线,上线后,需要考虑的是对各种服务进行监控,包括(httpd服务,mysqld服务等),现在想以mysqld服务为例总结下那种方式的脚本最为专业和合理: (1).根据mysql的端 ...

  7. make: g77: Command not found

    编译cblas时报错,这时,修改Makefile.in中的编译文件中的g77为gfortran

  8. C++多重继承子类和父类指针转换过程中的一个易错点

    这两天有个C++新手问了我一个问题,他的工程当中有一段代码执行不正确,不知道是什么原因.我调了一下,代码如果精简下来,大概是下面这个样子: class IBaseA { public: ; int m ...

  9. C 数据类型 长度

    ----数据类型长度 C99标准并不规定具体数据类型的长度大小.计算机具有不同位数的处理器,16,32和更高位的64位处理器,在这些不同的平台上,同一种数据类型具有不同的长度. char,short, ...

  10. cannot access the system temp folder

    cannot access the system temp folder. please, make sure your application have full control rights on ...