LeeDiculous
article thumbnail
Published 2023. 1. 3. 18:47
Linked List 중복값 삭제 알고리즘

이전 포스팅의 Linked List를 구현한 코드에서 추가로 중복값을 제거하는 기능을 추가하려 합니다.

아래의 메소드는 중복을 찾아내어 삭제해줍니다.

    void removeDups(){
        Node n = header;
        while(n != null && n.next != null){
            Node r = n;
            while(r.next != null){
                if(n.data == r.next.data){
                    r.next = r.next.next;
                }else {
                    r = r.next;
                }
            }
            n = n.next;
        }
    }

 

'알고리즘' 카테고리의 다른 글

Two Sum  (0) 2023.01.10
비트연산 - Bit Operation  (0) 2023.01.09
Linked List 개념  (0) 2023.01.03
최댓값과 최솟값  (0) 2022.12.29
LEVEL 1  (0) 2022.12.29
profile on loading

Loading...