gif via giphy
헤이-맨 기본에 충실해!
너 오늘 연결리스트 못 만들었어..
2시간 동안 면접을 봤다. 간단한 코딩인터뷰도 했는데 연결리스트를 만들어보는 문제도 같이 풀어보고 간단한 코드를 분석하는 시간도 가졌다. 와 진짜 당황해서 클래스 init함수도 다 까먹고 아무런 생각이 나지 않았다. 끝나고 나서 저녁먹고 혼자 생각해가면서 만들어보니까 5분만에 만들 수 있는 링크드리스트 예제를 땀을 뻘뻘 흘려가며 풀었다니(푼 것도 아니고 거의 다 알려주셨다.. 친절하게...) 진짜 배울게 너무 많다는 생각에 아주 짜릿하다.
그래도 이런 기회가 흔하지도 않고 지나고나서 생각해보면 너무 많이 배운 것 같다. 다만 아쉬운 건 조금만 덜 떨면서 침착하게 문제를 해결하려고 했다면 좋았을 것 같다. 그리고 마지막으로 클래스를 생성하고 클래수 내부함수 핸들하는 걸 반복숙달해가면서 연습해야겠다는 생각을 했다. 아무리 긴장을 해도 그렇지 클래스 초기화 함수도 생각이 안나고 while문도 거꾸로 적다니.. 개인적으로 충격이다.
면접에 관해서는 하고싶은 말이 많지만 자세한 얘기는 노션 오답노트에 작성해야겠다.
class Node():
def __init__(self,value):
self.next_node = None
self.value = value
class LinkedList():
def __init__(self):
self.head = None
def append(self, value):
if not self.head:
self.head = Node(value)
else:
cur_node = self.head
while cur_node.next_node:
cur_node = cur_node.next_node
cur_node.next_node = Node(value)
self._print()
def remove(self, value):
prev_node = None
cur_node = self.head
while cur_node:
if cur_node.value == value:
prev_node.next_node = cur_node.next_node
break
prev_node = cur_node
cur_node = cur_node.next_node
self._print()
def find(self, value):
cur_node = self.head
while cur_node:
if cur_node.value == value:
return cur_node
cur_node = cur_node.next_node
else: return None
def _print(self):
cur_node = self.head
while cur_node:
print(cur_node.value, end= " ")
if cur_node.next_node:
print("->", end= " ")
cur_node = cur_node.next_node
print()
linked_list = LinkedList()
linked_list.append(1)
linked_list.append(2)
linked_list.append(3)
linked_list.remove(2)
find_two = linked_list.find(3)
if find_two: print(find_two.value)
else: print(find_two)