본문 바로가기

Algorithms

싱글 링크드리스트 추가하기

주어진 노드 이전 뒤에 새 값을 추가하기: 

 

 

1. 지정된 값으로 새 노드 cur를 초기화

 

 

2. cur의 next 를 prev의 next node인 next 에 연결함

 

 

3. prev의 next를 cur에 연결시킴.

 

배열과 달리 삽입된 요소를 지나 모든 요소를 ​​이동할 필요가 없음.

따라서 O(1) 시간 복잡도를 가지는 링크드리스트에 새 노드를 삽입할 수 있으며 매우 효율적임.

 

 

 

https://leetcode.com/explore/learn/card/linked-list/209/singly-linked-list/1288/

 

Account Login - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com