Fork me on GitHub

83. 删除排序链表中的重复元素

class Solution {
public ListNode deleteDuplicates(ListNode head) {
		if (head == null)
			return null;
		ListNode ls = head;
		while (ls.next != null) {
			if (ls.val != ls.next.val) {
				ls = ls.next;
			} else {
				ls.next = ls.next.next;
			}
		}
		return head;
	}
}

posted @ 2019-07-22 15:18  cznczai  阅读(92)  评论(0编辑  收藏  举报