剑指offer
删除链表中重复的结点
相似的企业真题
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 64M,其他语言128M
热度指数:667996
本题知识点:
链表
算法知识视频讲解
校招时部分企业笔试将禁止编程题跳出页面,为提前适应,练习时请使用在线自测,而非本地IDE。
题目描述
在一个排序的链表中,存在重复的结点,请删除该链表中重复的结点,重复的结点不保留,返回链表头指针。 例如,链表1->2->3->3->4->4->5 处理后为 1->2->5
示例1
输入
复制
{1,2,3,3,4,4,5}
{1,2,3,3,4,4,5}
返回值
复制
{1,2,5}
{1,2,5}
说明:本题目包含复杂数据结构ListNode,
点此查看相关信息
上一题
下一题
登录
/
注册
我的提交
编辑器加载中...
/* public class ListNode { int val; ListNode next = null; ListNode(int val) { this.val = val; } } */ public class Solution { public ListNode deleteDuplication(ListNode pHead) { } }
/* struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { } }; */ class Solution { public: ListNode* deleteDuplication(ListNode* pHead) { } };
# -*- coding:utf-8 -*- # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: def deleteDuplication(self, pHead): # write code here
/* public class ListNode { public int val; public ListNode next; public ListNode (int x) { val = x; } }*/ class Solution { public ListNode deleteDuplication(ListNode pHead) { // write code here } }
/*function ListNode(x){ this.val = x; this.next = null; }*/ function deleteDuplication(pHead) { // write code here } module.exports = { deleteDuplication : deleteDuplication };
val = $x; } }*/ /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param pHead ListNode类 * @return ListNode类 */ function deleteDuplication( $pHead ) { // write code here }
/*function ListNode(x){ this.val = x; this.next = null; }*/ function deleteDuplication(pHead) { // write code here }
package main import . "nc_tools" /* * type ListNode struct{ * Val int * Next *ListNode * } */ /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param pHead ListNode类 * @return ListNode类 */ func deleteDuplication( pHead *ListNode ) *ListNode { // write code here }
# class ListNode # attr_accessor :val, :next # # def initialize(val = 0, _next = nil) # @val, @next = val, _next # end # end # # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # @param pHead ListNode类 # @return ListNode类 # class Solution def deleteDuplication(pHead) # write code here end end
/** * class ListNode(var val: Int) { * var next: ListNode = null * } */ object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param pHead ListNode类 * @return ListNode类 */ def deleteDuplication(pHead: ListNode): ListNode = { // write code here } }
/** * class ListNode(var `val`: Int) { * var next: ListNode? = null * } */ object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param pHead ListNode类 * @return ListNode类 */ fun deleteDuplication(pHead: ListNode?): ListNode? { // write code here } }
import java.util.*; /* * public class ListNode { * int val; * ListNode next = null; * public ListNode(int val) { * this.val = val; * } * } */ public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param pHead ListNode类 * @return ListNode类 */ public ListNode deleteDuplication (ListNode pHead) { // write code here } }
/*class ListNode { * val: number * next: ListNode | null * constructor(val?: number, next?: ListNode | null) { * this.val = (val===undefined ? 0 : val) * this.next = (next===undefined ? null : next) * } * } */ /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param pHead ListNode类 * @return ListNode类 */ export function deleteDuplication(pHead: ListNode): ListNode { // write code here }
/** * public class ListNode { * public var val: Int * public var next: ListNode? * public init(_ val: Int = 0, _ next: ListNode? = nil) { * self.val = val * self.next = next * } * } */ public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param pHead ListNode类 * @return ListNode类 */ func deleteDuplication ( _ pHead: ListNode?) -> ListNode? { // write code here } }
/** * #[derive(PartialEq, Eq, Debug, Clone)] * pub struct ListNode { * pub val: i32, * pub next: Option
> * } * * impl ListNode { * #[inline] * fn new(val: i32) -> Self { * ListNode { * val: val, * next: None, * } * } * } */ struct Solution{ } impl Solution { fn new() -> Self { Solution{} } /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param pHead ListNode类 * @return ListNode类 */ pub fn deleteDuplication(&self, pHead: Option
>) -> Option
> { // write code here } }
{1,2,3,3,4,4,5}
{1,2,5}