[LeetCode] 21. Merge Two Sorted Lists, Easy
·
CodingTest/LeetCode
1. 문제두 단일 연결 리스트가 정렬된 채로 주어질 때, 오름차순으로 정렬된 1개의 단일 연결리스트를 반환하라./** * Definition for singly-linked list. * class ListNode { * val: number * next: ListNode | null * constructor(val?: number, next?: ListNode | null) { * this.val = (val===undefined ? 0 : val) * this.next = (next===undefined ? null : next) * } * } */function mergeTwoLists(list1: ListNode | null, list2: ..
[LeetCode] 234. Palindrome Linked List, Easy
·
CodingTest/LeetCode
1. 문제단일 연결 리스트가 주어질 때, 팰린드롬 리스트 여부를 반환하라.팰린드롬 또는 회문 : 앞 뒤가 동일하게 구성되어 있는 것. madam, 12321 등등2. 해결/** * Definition for singly-linked list. * class ListNode { * val: number * next: ListNode | null * constructor(val?: number, next?: ListNode | null) { * this.val = (val===undefined ? 0 : val) * this.next = (next===undefined ? null : next) * } * } */function isPalindrome..
[LeetCode] 328. Odd Even Linked List, Medium
·
CodingTest/LeetCode
1. 문제단일 연결 리스트가 주어질 때, 값과 상관 없이 첫 번째 인덱스는 홀수, 두 번째 인덱스는 짝수와 같이 쭉 반복되는 형태일 때 홀수 그룹 리스트 + 짝수 그룹 리스트를 연결한 리스트를 반환하라.2. 해결/** * Definition for singly-linked list. * class ListNode { * val: number * next: ListNode | null * constructor(val?: number, next?: ListNode | null) { * this.val = (val===undefined ? 0 : val) * this.next = (next===undefined ? null : next) * } * } ..
[LeetCode] 203. Remove Linked List Elements, Easy
·
CodingTest/LeetCode
1. 문제단일 연결 리스트와 val가 주어질 때, val와 일치하는 노드를 제거한 리스트를 반환하라.2. 해결/** * Definition for singly-linked list. * class ListNode { * val: number * next: ListNode | null * constructor(val?: number, next?: ListNode | null) { * this.val = (val===undefined ? 0 : val) * this.next = (next===undefined ? null : next) * } * } */function removeElements(head: ListNode | null, val: num..
[LeetCode] 206. Reverse Linked List, Easy
·
CodingTest/LeetCode
1. 문제단일 연결 리스트가 주어질 때, 뒤집은 리스트를 반환하라.2. 해결/** * Definition for singly-linked list. * class ListNode { * val: number * next: ListNode | null * constructor(val?: number, next?: ListNode | null) { * this.val = (val===undefined ? 0 : val) * this.next = (next===undefined ? null : next) * } * } */function reverseList(head: ListNode | null): ListNode | null { if(!head..
[LeetCode] 19. Remove Nth Node From End of List, Medium
·
CodingTest/LeetCode
1. 문제연결 리스트와 정수 n이 주어질 때, n 번째 노드를 제외한 리스트를 반환하라.2. 해결/** * Definition for singly-linked list. * class ListNode { * val: number * next: ListNode | null * constructor(val?: number, next?: ListNode | null) { * this.val = (val===undefined ? 0 : val) * this.next = (next===undefined ? null : next) * } * } */function removeNthFromEnd(head: ListNode | null, n: number): L..
[LeetCode] 160. Intersection of Two Linked Lists, Easy
·
CodingTest/LeetCode
1. 문제단일 연결 리스트 headA, headB가 주어질 때, 두 연결 리스트의 요소 중 동일한 주소를 가지는 첫 번째 노드를 반환하라.만약, 없다면 null을 반환하라.2. 해결/** * Definition for singly-linked list. * class ListNode { * val: number * next: ListNode | null * constructor(val?: number, next?: ListNode | null) { * this.val = (val===undefined ? 0 : val) * this.next = (next===undefined ? null : next) * } * } */function getInt..
[LeetCode] 142. Linked List Cycle II, Medium
·
CodingTest/LeetCode
1. 문제연결 리스트 head가 주어질 때, 사이클의 시작 노드를 반환하라. pos는 주어지지 않는다.2. 해결/** * Definition for singly-linked list. * class ListNode { * val: number * next: ListNode | null * constructor(val?: number, next?: ListNode | null) { * this.val = (val===undefined ? 0 : val) * this.next = (next===undefined ? null : next) * } * } */function detectCycle(head: ListNode | null): ListNode ..
[LeetCode] 141. Linked List Cycle, Easy
·
CodingTest/LeetCode
1. 문제연결 리스트의 head가 주어질 때, 해당 리스트 내 사이클이 존재하는 지 true 또는 false를 반환하라.pos는 전달되지 않는 값이다.2. 해결/** * Definition for singly-linked list. * class ListNode { * val: number * next: ListNode | null * constructor(val?: number, next?: ListNode | null) { * this.val = (val===undefined ? 0 : val) * this.next = (next===undefined ? null : next) * } * } */function hasCycle(head: Lis..
[LeetCode] 707. Design Linked List, Medium
·
CodingTest/LeetCode
1. 문제단일 연결 리스트 혹은 이중 연결 리스트를 만들어라. 조건은 다음과 같다.생성자로 객체를 생성하며, 매개변수는 받지 않는다.get 함수는 index를 매개변수로 받고 해당 인덱스의 value롤 반환하고, 없으면 -1을 반환하라.addAtHead 함수는 새로운 노드를 연결 리스트의 맨 처음에 추가하라.addAtTail 함수는 새로운 노드를 연결 리스트의 맨 마지막에 추가하라.addAtIndex 함수는 주어진 인덱스에 새로운 노드를 추가하되, 만약 인덱스가 전체 길이와 같을 때도 추가하고 전체 길이보다 큰 경우는 무시한다.deleteAtIndex 함수는 해당 index의 노드를 제거하라.2. 해결class Node { // 노드 클래스 value: number; next: Node | n..