一、题目内容

image.png

二、题解

解法1:

思路

双指针追走

代码

  1. public class Solution {
  2. public ListNode deleteDuplicates (ListNode head) {
  3. // write code here
  4. ListNode cur = head;
  5. if(cur == null){
  6. return head;
  7. }
  8. while(cur.next!=null){
  9. if(cur.val == cur.next.val){
  10. cur.next = cur.next.next;
  11. }else{
  12. cur = cur.next;
  13. }
  14. }
  15. return head;
  16. }
  17. }