• LeetCode 83 Remove Duplicates from Sorted List


    相同的时候,prev指针不动,cur.next = cur.next.next

    不相同的时候, prev跟cur指针同时更新。

     1 /**
     2  * class ListNode {
     3  *   public int value;
     4  *   public ListNode next;
     5  *   public ListNode(int value) {
     6  *     this.value = value;
     7  *     next = null;
     8  *   }
     9  * }
    10  */
    11 public class Solution {
    12   public ListNode removeDup(ListNode head) {
    13     // Write your solution here
    14     if (head == null) {
    15          return head; 
    16     }
    17     ListNode prev = head, cur = head;
    18     while (cur.next != null) {
    19         if (cur.value == cur.next.value) {
    20           cur.next = cur.next.next; 
    21       } else {
    22         prev = cur;
    23            cur = cur.next;
    24       }
    25     }
    26     return head;
    27   }
    28 }
  • 相关阅读:
    202011.19
    202011.18
    202011.17
    202011.16
    202011.14
    jdk的下载和配置
    layui中form表单
    JS中utocomplete
    转:JqueryUI学习笔记-自动完成autocomplete
    JSON.parse()与JSON.stringify()的区别
  • 原文地址:https://www.cnblogs.com/mayinmiao/p/8491383.html
Copyright © 2020-2023  润新知