개발공부/LeetCode

    [JavaScript] 138. Copy List with Random Pointer, 해시맵 사용, 쉬운설명

    [JavaScript] 138. Copy List with Random Pointer, 해시맵 사용, 쉬운설명

    138. Copy List with Random Pointer A linked list of length n is given such that each node contains an additional random pointer, which could point to any node in the list, or null. n의 길이를 하고있는, 링크리스트가있고, 각 노드는 노말 포인터와, 랜덤 포인터를 가지고있고 이 랜덤 포인터는 리스트에 포함된 아무 노드나 null값을 가르킵니다. Construct a deep copy of the list. The deep copy should consist of exactly n brand new nodes, where each new node has its val..

    [JavaScript] 61. Rotate List Medium  - 연결리스트 노드 옮기기, 쉬운설명, 반복문 사용

    [JavaScript] 61. Rotate List Medium - 연결리스트 노드 옮기기, 쉬운설명, 반복문 사용

    61. Rotate List Given the head of a linked list, rotate the list to the right by k places. Example 1: Input: head = [1,2,3,4,5], k = 2 Output: [4,5,1,2,3] Example 2: Input: head = [0,1,2], k = 4 Output: [2,0,1] 계획 문제 해결 전략 주어진 k만큼 반복하게 됩니다. 하지만 k가 linkedlist의 길이보다 클경우, example 2와 같이 k를 linkedlist length로 나눈 나머지값 만큼만 반복하면되기때문에 반복문에서 k% linkedlistLength의 값만큼 반복하게 합니다. linkedList 특성상 index로 요구하는 위치..

    [JavaScript] 21. Merge Two Sorted Lists - 쉬운설명

    [JavaScript] 21. Merge Two Sorted Lists - 쉬운설명

    21. Merge Two Sorted Lists You are given the heads of two sorted linked lists list1 and list2. Merge the two lists in a one sorted list. The list should be made by splicing together the nodes of the first two lists. Return the head of the merged linked list. Example 1: Input: list1 = [1,2,4], list2 = [1,3,4] Output: [1,1,2,3,4,4] Example 2: Input: list1 = [], list2 = [] Output: [] Example 3: Inp..

    [JavaScript] 206. Reverse Linked List - 쉬운설명, 인터뷰 필수 문제

    [JavaScript] 206. Reverse Linked List - 쉬운설명, 인터뷰 필수 문제

    206. Reverse Linked List - Easy Given the head of a singly linked list, reverse the list, and return the reversed list. Example 1: Input: head = [1,2,3,4,5] Output: [5,4,3,2,1] Example 2: Input: head = [1,2] Output: [2,1] Example 3: Input: head = [] Output: [] 해설 문제 해결 전략 릿코드 디스커션에서 가져온 이미지입니다. 이미지를 설명하자면, 3개의 포인터 current next prev를 사용하여 LinkedList를 reverse 해주는 것을 확인할수있습니다. 구현 전략 prev, current,..