Programmers/데브코스 인공지능

[프로그래머스 스쿨 AI] Day 1 7강 연결 리스트(Linked Lists)

1. 연결 리스트(Linked Lists) 

1. 연결 리스트

node를 활용해서 하나에 줄에 줄줄이 종이를 이어 붙이는거 같다

2. 문제 풀이

1. 연결 리스트 순회 구현하기

 

class Node:
    def __init__(self, item):
        self.data = item
        self.next = None

class LinkedList:
    def __init__(self):
        self.nodeCount = 0
        self.head = None
        self.tail = None

    def getAt(self, pos):
        if pos < 1 or pos > self.nodeCount:
            return None
        i = 1
        curr = self.head
        while i < pos:
            curr = curr.next
            i += 1
        return curr

    def traverse(self):
        if not self.head:
            return []
        gogo = self.head
        listmaker = []
        while gogo.next:
            listmaker.append(gogo.data)
            gogo = gogo.next
        listmaker.append(gogo.data)
        return listmaker


# 이 solution 함수는 그대로 두어야 합니다.
def solution(x):
    return 0

3. 코딩후기

생각보다 이미 있는 코드를 분석하고 구동을 이해하기가 오래걸린다