0
点赞
收藏
分享

微信扫一扫

解决java发邮件错误javax.net.ssl.SSLHandshakeException: No appropriate protocol

color_小浣熊 2023-11-18 阅读 46

文章目录

思路

解题方法

复杂度

  • 时间复杂度:
  • 空间复杂度:

Code


/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
class Solution {
    //Time Complexity: O(n)
    //Space Complexity: O(1)
    public ListNode deleteDuplicates(ListNode head) {
        if (head == null) return null;
        ListNode dummyNode = new ListNode(Integer.MAX_VALUE,head);
        ListNode tail = dummyNode;
        while (tail.next != null && tail.next.next != null) {
            //出现重复
            if (tail.next.val == tail.next.next.val) {
                ListNode noReptition = tail.next;
                while (noReptition != null && noReptition.val == tail.next.val) {
                    noReptition = noReptition.next;
                }
                tail.next = noReptition;
            } else {
                tail = tail.next;
            }
        }
         return dummyNode.next;
    }
}
举报

相关推荐

0 条评论