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     }
  • 相关阅读:
    JDK6的switch支持不是很好
    团队作业(2)
    团队作业(1)
    4月30日
    重构:改善既有代码的设计有感
    4月28日
    4月27日
    4月26日
    4月25日
    4月24日
  • 原文地址:https://www.cnblogs.com/davidnyc/p/8460693.html
Copyright © 2011-2022 走看看