
전체 글
LeetCode / Linked List / 876번 / Middle of Linked List / JS
Middle of the Linked List - LeetCode Can you solve this real interview question? Middle of the Linked List - Given the head of a singly linked list, return the middle node of the linked list. If there are two middle nodes, return the second middle node. Example 1: [https://assets.leetcode. leetcode.com 여러개의 노드로 연결된 linked list에서 중간 노드를 반환하면 되는 문제이다. 만약 노드의 개수가 짝수라면 중간 노드의 ..
백준 / 백트래킹 / 15654번 / N과 M (5) / JS
15654번: N과 M (5) N개의 자연수와 자연수 M이 주어졌을 때, 아래 조건을 만족하는 길이가 M인 수열을 모두 구하는 프로그램을 작성하시오. N개의 자연수는 모두 다른 수이다. N개의 자연수 중에서 M개를 고른 수열 www.acmicpc.net /* N과 M (5) */ const fs = require('fs'); // const filePath = process.platform === 'linux' ? '/dev/stdin' : '../input.txt'; const filePath = process.platform === 'linux' ? '/dev/stdin' : 'BOJ/input.txt'; const input = fs.readFileSync(filePath).t..
Object Method
ObjectObject 클래스는 JavaScript의 데이터 유형 중 하나를 나타낸다. 다양한 키 모음 및 더 복잡한 엔티티들을 저장하는 데 사용된다. JS의 거의 모든 객체는 Object의 인스턴스이다. JS는 객체 기반의 스크립트 언어이다. 원시 타입을 제외한 나머지는 모두 객체이다. 한마디로 JS는 객체빼면 시체다... 객체는 키(key)와 값(value)쌍으로 이루어진 프로퍼티(property)들의 집합이다.const obj = { key: value, ... }; Object.entries()for...in와 같은 순서로 주어진 객체 자체의 enumerable 속성 [key, value] 쌍의 배열을 반환한다.Object.entries() 에 의해 반환된 배열(array)의 순서는 객체가 정의된..
Array Method
Array 배열은 리스트와 비슷한 '객체'이다. JS의 배열은 길이도 고정되어 있지 않고, 요소의 자료형도 고정되어 있지 않다. 따라서 한 배열에 숫자와 문자열이 같이 들어갈 수도 있고, 아래와 같이 그냥 뒤에 값을 넣을 수도 있다. let arr = [1, 2]; arr[2] = 3; console.log(arr); // [1, 2, 3] 또한 위와 같이 그냥 리터럴 표기법으로 배열을 생성할 수도 있고, 생성자로 생성할 수 있다. 이제 아래에서 생성자를 시작으로 관련 메소드들을 알아보자. Array() 생성자 let arr1 = new Array(3); console.log(arr1); // [empty * 3] console.log(arr1[0]); // undefined 위 코드와 같이 '빈 슬롯'..

LeetCode / Linked List / 206번 / Reverse Linked List / JS
Reverse Linked List - LeetCode Can you solve this real interview question? Reverse Linked List - Given the head of a singly linked list, reverse the list, and return the reversed list. Example 1: [https://assets.leetcode.com/uploads/2021/02/19/rev1ex1.jpg] Input: head = [1,2,3,4,5] O leetcode.com 주어진 Linked List의 노드의 순서를 반대로 바꾸면 되는 문제이다. /** * Definition for singly-linked..

LeetCode / Linked List / 21번 / Merge Two Sorted Lists / JS
Merge Two Sorted Lists - LeetCode Can you solve this real interview question? 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 leetcode.com 주어진 두개의 Linked List를 하나의 List로 Merge하여 오름차순으로 정렬하면 되는 문제이다. /** * Defi..