zoukankan      html  css  js  c++  java
  • [leetcode]Remove Duplicates from Sorted List @ Python

    原题地址:https://oj.leetcode.com/problems/remove-duplicates-from-sorted-list/

    题意:

    Given a sorted linked list, delete all duplicates such that each element appear only once.

    For example,
    Given 1->1->2, return 1->2.
    Given 1->1->2->3->3, return 1->2->3.

    解题思路:链表节点的去重。比较简单。

    代码:

    # Definition for singly-linked list.
    # class ListNode:
    #     def __init__(self, x):
    #         self.val = x
    #         self.next = None
    
    class Solution:
        # @param head, a ListNode
        # @return a ListNode
        def deleteDuplicates(self, head):
            if head == None or head.next == None:
                return head
            p = head
            while p.next:
                if p.val == p.next.val:
                    p.next = p.next.next
                else:
                    p = p.next
            return head
  • 相关阅读:
    JavaScript基础学习篇
    js,html,css注释大集合
    JS中的专业术语
    BFC给我的帮助以及对hasLayout的认识
    框架
    PHP echo和print语句
    PHP变量
    PHP语法
    PHP入门
    SQLite学习网址
  • 原文地址:https://www.cnblogs.com/zuoyuan/p/3783466.html
Copyright © 2011-2022 走看看