题目描述:

Remove all elements from a linked list of integers that have value val.

Example
Given: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6
Return: 1 --> 2 --> 3 --> 4 --> 5

解题思路:

链表操作。

代码如下:

/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
public class Solution {
public ListNode removeElements(ListNode head, int val) {
ListNode res = new ListNode(0);
res.next = head;
ListNode point = head, pre = res; while(point != null) {
if(point.val == val) {
if(point.next != null) {
point.val = point.next.val;
point.next = point.next.next;
} else {
point = null;
pre.next = null;
}
} else {
point = point.next;
pre = pre.next;
}
}
return res.next;
}
}

  

最新文章

  1. Spring框架总结
  2. Linux定时任务Crontab学习笔记
  3. python datetime处理时间
  4. win7下matplotlib安装(64位)
  5. Node入门
  6. 【转载】关于initrd.image的处理
  7. 在ASP.Net和IIS中删除不必要的HTTP响应头
  8. Android消息机制——时钟显示和异步处理工具类(AsyncTask)
  9. Sql Server中的分组
  10. 关于键盘冲突那点事(3键冲突/7键冲突/PS2/USB的各种原理)
  11. toString&&equals方法
  12. hadoop 异常 INFO ipc.Client: Retrying connect to server:
  13. 南阳师范学院ACM集训队博客使用方法
  14. IOS学习1——IOS应用程序的生命周期及基本架构
  15. Java多线程模型
  16. 构建具有用户身份认证的 Ionic 应用
  17. qlikview 权限管理和sso集成
  18. 1.hive开窗函数,分析函数
  19. Linux 文件特殊权限详解[suid/sgid/t]
  20. makefile--参数传递、条件判断、include (五)

热门文章

  1. Leetcode#78 Subsets
  2. matlab fscanf用法
  3. 【WCF--初入江湖】目录
  4. running android lint has encountered a problem
  5. 【leetcode】Majority Element (easy)(*^__^*)
  6. HDU 1227 Fast Food (DP)
  7. Project Euler 80:Square root digital expansion 平方根数字展开
  8. GDB笔记
  9. 【Linux高频命令专题(18)】tail
  10. 银联接口(注意项&备忘)