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. 코딩후기
생각보다 이미 있는 코드를 분석하고 구동을 이해하기가 오래걸린다
'Programmers > 데브코스 인공지능' 카테고리의 다른 글
[프로그래머스 스쿨 AI] Week 2 jupyter notebook 실행에러[window] (0) | 2021.04.26 |
---|---|
[프로그래머스 스쿨 AI] Day 1 8강 연결 리스트(Linked List) (0) | 2021.04.20 |
[프로그래머스 스쿨 AI] Day 1 6강 알고리즘의 복잡도 (0) | 2021.04.20 |
[프로그래머스 스쿨 AI] Day 1 5강 재귀적 이진 탐색 구현하기 (0) | 2021.04.20 |
[프로그래머스 스쿨 AI] Day 1 4강 재귀 알고리즘 기초 (0) | 2021.04.20 |