题解 | #删除有序链表中重复的元素-I#
删除有序链表中重复的元素-I
http://www.nowcoder.com/practice/c087914fae584da886a0091e877f2c79
package main import . "nc_tools" /* //递归 func deleteDuplicates( head *ListNode ) *ListNode { // write code here if head == nil || head.Next == nil { return head } head.Next = deleteDuplicates(head.Next) if head.Val == head.Next.Val { head = head.Next } return head } */ //迭代 func deleteDuplicates( head *ListNode) *ListNode { if head == nil || head.Next == nil { return head } cur := head for cur.Next != nil { if cur.Val == cur.Next.Val { cur.Next = cur.Next.Next } else { cur = cur.Next } } return head }