전체 글 383

[Leet Code - eazy] 1281. Subtract the Product and Sum of Digits of an Integer

Given an integer number n, return the difference between the product of its digits and the sum of its digits. Example 1: Input: n = 234 Output: 15 Explanation: Product of digits = 2 * 3 * 4 = 24 Sum of digits = 2 + 3 + 4 = 9 Result = 24 - 9 = 15 Example 2: Input: n = 4421 Output: 21 Explanation: Product of digits = 4 * 4 * 2 * 1 = 32 Sum of digits = 4 + 4 + 2 + 1 = 11 Result = 32 - 11 = 21 Const..

[프로그래머스] k의 개수

문제 설명 1부터 13까지의 수에서, 1은 1, 10, 11, 12, 13 이렇게 총 6번 등장합니다. 정수 i, j, k가 매개변수로 주어질 때, i부터 j까지 k가 몇 번 등장하는지 return 하도록 solution 함수를 완성해주세요. 제한사항 1 ≤ i { if(num == k){ answer++ } }) }) return answer; } Colored by Color Scripter cs 문제를 풀며 느낀 점 - 먼저 반복문을 통해서 i부터 j까지의 수를 String으로 형 변환을 한 값을 arr 배열에 할당하였고 arr을 forEach()를 통해서 하나 하나 순회하면서 들어온 nums값을 split('')함수를 통해서 한자릿수씩 자른뒤 그걸 forEach()를 통해서 읽은 뒤 num의 값이..

[프로그래머스] 직각삼각형 출력하기

문제 설명 "*"의 높이와 너비를 1이라고 했을 때, "*"을 이용해 직각 이등변 삼각형을 그리려고합니다. 정수 n 이 주어지면 높이와 너비가 n 인 직각 이등변 삼각형을 출력하도록 코드를 작성해보세요. 입출력 예 입력 #1 3 출력 #1 * ** *** 나의 풀이 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 const readline = require('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); let input = []; rl.on('line', function (line) { input = line.spl..

React props와 state

제로베이스 강의 중 이해가 빠른 일취월장 리액트를 수강하면서 기억해야 될 점을 적어볼까 합니다. 먼저 props는 부모 컴포넌트가 자식 컴포넌트에게 전달하는 값입니다. 강의에서 자식 컴포넌트에서 props를 전달받을 때는 props.(전달받은 name)등으로 받았던 것 같고 이름이 정해지지 않고 사이에 추가 한 값이라면 props.children으로 받았던 것 같습니다. 또한 자식 컴포넌트에서는 전달 받은 props의 값을 변경할 수 없습니다. 다음으로 state는 컴포넌트에서 스스로 관리하는 상태 값 입니다. JS에서는 값이 변경되어서 rerendarin을 해주고 싶을 때는 함수를 재 호출 하는 방식으로 했었던 것 같은데 React에서는 원하는 부분만 동적으로 변경하기 위해서 useState() 함수를..

[프로그래머스] 합성수 찾기

문제 설명 약수의 개수가 세 개 이상인 수를 합성수라고 합니다. 자연수 n이 매개변수로 주어질 때 n이하의 합성수의 개수를 return하도록 solution 함수를 완성해주세요. 제한사항 1 ≤ n ≤ 100 입출력 예 n result 10 5 15 8 입출력 예 #1 10 이하 합성수는 4, 6, 8, 9, 10 로 5개입니다. 따라서 5를 return합니다. 입출력 예 #1 15 이하 합성수는 4, 6, 8, 9, 10, 12, 14, 15 로 8개입니다. 따라서 8을 return합니다. 나의 풀이 1 2 3 4 5 6 7 8 9 10 function solution(n) { let arr = new Set(); for(let i = 1; i

[Leet Code - eazy] 2160. Minimum Sum of Four Digit Number After Splitting Digits

You are given a positive integer num consisting of exactly four digits. Split num into two new integers new1 and new2 by using the digits found in num. Leading zeros are allowed in new1 and new2, and all the digits found in num must be used. For example, given num = 2932, you have the following digits: two 2's, one 9 and one 3. Some of the possible pairs [new1, new2] are [22, 93], [23, 92], [223..

[Leet Code - eazy] 2114. Maximum Number of Words Found in Sentences

A sentence is a list of words that are separated by a single space with no leading or trailing spaces. You are given an array of strings sentences, where each sentences[i] represents a single sentence. Return the maximum number of words that appear in a single sentence. Example 1: Input: sentences = ["alice and bob love leetcode", "i think so too", "this is great thanks very much"] Output: 6 Exp..