문제https://school.programmers.co.kr/learn/courses/30/lessons/12931 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr 풀이법자연수 N 의 각 자리의 합을 구해라 → 자연수를 배열로 변경해서 배열을 돌면서 요소들을 더하면 되겠다! 하고 생각했다. 우선 자연수를 배열로 변경하려면 문자열로 먼저 변경하는 과정이 필요하다. 문자열로 변경 후 문자열을 배열로 변경하는 것은 Array.from() 을 사용하였고, 배열을 순회하면서 모든 요소를 더하는 것은 reduce() 를 사용하였다. 코드const solution = (..
문제https://school.programmers.co.kr/learn/courses/30/lessons/120803?language=javascript 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr 코드function solution(num1, num2) { return num1 - num2;} 시간복잡도num1 과 num2 을 빼는 연산은 상수 시간을 소요한다. 따라서 시간복잡도는 O(1)이다. 즉, 입력 크기와 관계없이 일정한 시간이 소요된다.해당 코드에서는 두 개의 숫자를 입력받고, 두 숫자에 대한 단순 뺄셈 연산만 실행한다. 따라서 입력되는 ..
문제https://www.acmicpc.net/problem/10828 정답const fs = require("fs");const filePath = process.platform === "linux" ? "/dev/stdin" : "./input.txt";const input = fs.readFileSync(filePath).toString().split("\n");class Stack { #array; constructor(array = []) { this.#array = array; } push(value) { return this.#array.push(value); } pop() { if (this.#array.length === 0) { return -1; ..
문제https://www.acmicpc.net/problem/10430 정답const fs = require("fs");const filePath = process.platform === "linux" ? "/dev/stdin" : "./input.txt";const input = fs.readFileSync(filePath).toString().split(" ");const numberArr = input.map((i) => parseInt(i));function solution(input) { const A = input[0]; const B = input[1]; const C = input[2]; console.log((A + B) % C); console.log(((A % C) + (B ..
문제https://www.acmicpc.net/problem/1874 정답 코드const fs = require("fs");const filePath = process.platform === "linux" ? "/dev/stdin" : "./input.txt";const input = fs .readFileSync(filePath) .toString() .split("\n") .map((i) => Number(i));function solution(input) { const result = []; const count = input[0]; const stack = []; let stackNumber = 1; for (let i = 1; i 풀이문제를 읽고 어떻게 풀라는 것인지 이해가 안..
문제https://www.acmicpc.net/problem/2753 정답 코드const fs = require("fs");const filePath = process.platform === "linux" ? "/dev/stdin" : "./input.txt";const input = fs.readFileSync(filePath).toString().trim();const isLeapYear = (year) => { if (year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0)) { return true; } else { return false; }};/** * 연도가 주어졌을 때 * 윤년이면 1 출력 * 아니면 0 출력 */function ..