zoukankan      html  css  js  c++  java
  • LC_83. Remove Duplicates from Sorted List

    https://leetcode.com/problems/remove-duplicates-from-sorted-list/description/
    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.

     1 public ListNode deleteDuplicates(ListNode head) {
     2         if (head == null || head.next == null) return head ;
     3         ListNode curr = head ;
     4         /*
     5         * 重点体会跳过去是什么意思 CURR =HEAD 然后改变 CURR.NEXT HEAD.next 也是会被变化的
     6         * */
     7         /*
     8         *  1-1-1-1-2-2-3
     9         *  c--->
    10         *   ---->
    11         *   ------->
    12         *          c
    13         *  h------->
    14         * */
    15         while(curr.next!=null){
    16             if (curr.val == curr.next.val){
    17                 curr.next = curr.next.next ;
    18             } else {
    19                 curr = curr.next ;
    20             }
    21         }
    22         return head ;
    23     }
  • 相关阅读:
    Promise
    includes()
    常见的数组去重方法
    concat()
    面试感想
    常见的前端面试题
    让div水平垂直居中的几种方法
    实现斐波拉契的几种方法
    使用lib-flexible
    什么是token
  • 原文地址:https://www.cnblogs.com/davidnyc/p/8460693.html
Copyright © 2011-2022 走看看