On wed,

  1. Doubly linked list
  2. leetcode review problem 진행

Problem

Singly linked list 는 needs O(N) time complexity even when we know what to remove.

10번째 지우고 싶어도 9, 11을 알아야 둘을 이어준다.

answer

그러면 한 node에서 양쪽으로 이어주면 되는 것 아닌가?

Doubly linked list의 탄생!

image.png

*의 설명처럼 node가 given이면 O(1)으로 줄어든다.

  1. Leetcode problem

image.png

head가 주어지고, linked list에게 cycle 이 있는지 알아보는 tesk

node에 이미 지나갔는지 아닌지를 indicate 하는 variable을 하나 더 정의해놓고 iterration 돌면서 검사하는 방법!

before

image.png