[LeetCode] 83. Remove Duplicates from Sorted List

2023. 3. 10. 14:59·Problem Solving/LeetCode

출처 : https://leetcode.com/problems/remove-duplicates-from-sorted-list/

 

Remove Duplicates from Sorted List - LeetCode

Can you solve this real interview question? Remove Duplicates from Sorted List - Given the head of a sorted linked list, delete all duplicates such that each element appears only once. Return the linked list sorted as well.   Example 1: [https://assets.le

leetcode.com

 

 

 

/**
 * 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 {
    public ListNode deleteDuplicates(ListNode head) {
        if(head == null) return null;
        ListNode node = head;
        while(node != null && node.next != null) {
            if(node.val == node.next.val) {
                node.next = node.next.next;
            }
            else {
                node = node.next;
            }
        }
        return head;
        
        
    }
}
'Problem Solving/LeetCode' 카테고리의 다른 글
  • [LeetCode] 33. Search in Rotated Sorted Array.
  • [LeetCode] 88. Merge Sorted Array
  • [LeetCode] 94. Binary Tree Inorder Traversal
  • [LeetCode] 101. Symmetric Tree
kimdozzi
kimdozzi
끝까지 포기하지 않으면, 내가 다 이겨!
  • kimdozzi
    도브로
    kimdozzi
  • 전체
    오늘
    어제
    • 분류 전체보기 (132)
      • Problem Solving (49)
        • Baekjoon (29)
        • Programmers (0)
        • LeetCode (17)
        • 삼성 유형 (2)
      • Computer Science (27)
        • Operating System (2)
        • Algorithms (13)
        • Network (6)
        • DataBase (6)
      • Backend (33)
        • JavaScript (0)
        • TypeScript (6)
        • Java (7)
        • Spring Boot (7)
        • Spring Security (6)
        • JPA (2)
        • Mybatis (1)
        • Junit5 (1)
        • Redis (3)
      • DevOps (14)
        • Git, Github (5)
        • docker (4)
        • AWS (3)
        • nginx (2)
      • etc (6)
        • IntelliJ (3)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
    • 티스토리
    • 설정
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    CORS
    interface
    누적합
    docker image
    세그먼트 트리
    docker
    PrefixSum
    티스토리챌린지
    python
    구간합
    인터페이스
    오블완
    segment tree
    온라인 쿼리
    도커
    파이썬
    타입스크립트
    컨테이너
    오프라인 쿼리
    Bucket
    인덱스 시그니처
    점 업데이트
    AWS
    imos법
    구간 업데이트
    알고리즘
    백준
    인덱서블 타입
    S3
    TypeScript
    삼성기출
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.0
kimdozzi
[LeetCode] 83. Remove Duplicates from Sorted List
상단으로

티스토리툴바