博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Remove Linked List Elements
阅读量:4074 次
发布时间:2019-05-25

本文共 795 字,大约阅读时间需要 2 分钟。

Remove Linked List Elements

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

Credits:
Special thanks to  for adding this problem and creating all test cases.

Java代码:

/** * 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) {        if(null == head)			return head;		while(head.val == val){			head = head.next;			if(null == head)				return head;		}				ListNode tmp = head;		while(tmp.next !=null){			if(tmp.next.val ==val){				tmp.next = tmp.next.next;			}else{				tmp = tmp.next;			}					}		return head;    }}

转载地址:http://pvuni.baihongyu.com/

你可能感兴趣的文章
vector3.forward和transform.forward的区别!
查看>>
HOLOLENS的空间管理
查看>>
unity3d 的Quaternion.identity和transform.rotation区别是什么
查看>>
【Unity3d】Ray射线初探-射线的原理及用法
查看>>
迄今最深入、最专业的Hololens评测结果,美国AR大咖艾迪·奥夫曼现身说法
查看>>
全息眼镜HoloLens可快速捕捉真人3D图像
查看>>
copy-paste component
查看>>
【Unity】矩阵运算
查看>>
理解向量运算
查看>>
正弦 sin 余弦 cos
查看>>
微积分
查看>>
Vector3 *2 ,ToString()自动四舍五入
查看>>
2016年秋季的我,work with hololens
查看>>
叉积与点积
查看>>
λ怎么 读
查看>>
Rect 和 Bounds
查看>>
HOLOLENS不适合加天空盒
查看>>
Unity UI on hololens
查看>>
Unity 下载存档
查看>>
3D游戏常用技巧Normal Mapping (法线贴图)原理解析——基础篇
查看>>