原创

[百战LeetCode][17.删除有序链表中重复元素-I]


==========================努力奋斗财源广进==========================

一、算法题目

删除给出链表中的重复元素(链表中元素从小到大有序),使链表中的所有元素都只出现一次。

二、题解

1、我的题解

import java.util.*;

/*
 * public class ListNode {
 *   int val;
 *   ListNode next = null;
 * }
 */

public class Solution {
    /**
     * 
     * @param head ListNode类 
     * @return ListNode类
     */
    public ListNode deleteDuplicates (ListNode head) {
        // write code here
        //题目简单死了。
        if(head == null || head.next == null) 
        {
            return head;
        }
        ListNode cur = head;
        while(cur != null && cur.next != null){
            int val = cur.val;
            if(val == cur.next.val){
                cur.next = cur.next.next;
            } else{
                cur = cur.next;
            }
        }
        return head;
    }
}

2、优秀题解

//待定

三、解法心得

此题比较简单,只要理清脉络,就能很快的解体出来。

四、自我监督

评论区记录复习记录

算法刷题
  • 作者:北斗七点半联系作者
  • 发表时间:2022-07-16 20:15
  • 版权声明:禁止转载
  • 非公众号转发
  • 评论