zoukankan      html  css  js  c++  java
  • LeetCode83. 删除排序链表中的重复元素

    判断当前节点currentNode的值和它的next指针所指向的节点的值是否相等,如果相等,就一直向后移动next指针直到遇到
    next指针所指节点的值和currentNode的值不相等,这时将currentNode的next指针指向这个不相等的节点即可。
    当currentNode和currentNode的next指针都为空时退出while循环,表示扫描链表结束(currentNode为空表示链表末尾已经指向NULL)。

    class Solution {
    public:
        ListNode* deleteDuplicates(ListNode* head) {
            auto currentNode = head;
            while(currentNode && currentNode -> next) {
                if(currentNode -> val == currentNode -> next -> val) {
                    currentNode -> next = currentNode -> next -> next;
                } else {
                    currentNode = currentNode -> next;
                }
            }
            return head;
        }
    };
    
  • 相关阅读:
    Bluedroid介绍
    Android蓝牙介绍
    Android Bluetooth抓包
    Bluetooth LMP介绍
    Bluetooth Baseband介绍
    Bluetooth SDP介绍
    Bluetooth HFP介绍
    Bluetooth RFCOMM介绍
    Bluetooth L2CAP介绍
    Windows开发
  • 原文地址:https://www.cnblogs.com/linrj/p/13255936.html
Copyright © 2011-2022 走看看