이노베이션 캠프/3주차_알고리즘
-
[JS] 체육복이노베이션 캠프/3주차_알고리즘 2023. 6. 21. 19:23
문제 https://school.programmers.co.kr/learn/courses/30/lessons/42862 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 문제 풀이 function solution(n, lost, reserve) { // 1) 서로에게 중복되는 값 제거, 테스트 데이터에서 lost와 reserve에 중복 되는 경우 존재 let losts = lost.filter((a) => !reserve.includes(a)); let reserves = reserve.filter((a) => !lost.includes(a) ); // 2)..
-
[JS] 실패율이노베이션 캠프/3주차_알고리즘 2023. 6. 21. 17:27
문제 https://school.programmers.co.kr/learn/courses/30/lessons/42889 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 문제 풀이 function solution(N, stages) { let result = []; // 1) 결과 값 저장할 변수 // 2) for문 사용하여 주어진 스테이지의 수만큼 반복 for (let i=1; i s >= i).length; // 2-1) 스테이지에 도달한 플레이어 수 let fails = stages.filter((s) => s === i).length; // 2-2) ..
-
[JS] 크레인 인형뽑기 게임이노베이션 캠프/3주차_알고리즘 2023. 6. 21. 14:37
문제 https://school.programmers.co.kr/learn/courses/30/lessons/64061 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 문제 풀이 function pickDoll(arr, index) { // 인형 꺼내주는 함수 let val = 0; // 1) 인형 정보 저장할 변수 // 2) for문 사용하여 배열의 모든 요소에 접근 for (let i=0; i
-
[JS] 다트 게임 (1차)이노베이션 캠프/3주차_알고리즘 2023. 6. 21. 14:32
문제 https://school.programmers.co.kr/learn/courses/30/lessons/17682 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 문제 풀이 function solution(dartResult) { let result = []; // 1) 결과 값을 저장한 변수 선언 및 할당 let pat = /\d+[A-Z][*#]?/g; // 2) 값을 잘라올 수 있는 패턴 생성 let gameResults = dartResult.match(pat); // 3) match 사용하여 생성된 패턴과 일치하는 문자열 배열로 저장 let ..
-
[JS] 비밀지도이노베이션 캠프/3주차_알고리즘 2023. 6. 21. 14:24
문제 https://school.programmers.co.kr/learn/courses/30/lessons/17681 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 문제 풀이 function changBin(num, n) { // 10진수를 2진수로 변경해주는 함수 let bin = num.toString(2); // 1) 2진수로 변경 (string형) let len = bin.length;// 2) 변경한 2진수의 길이 저장 if (len >= n) return bin; // 3) 2진수로 변경한 값이 입력된 길이 값과 동일한 경우 리턴 return..
-
[JS] 폰켓몬이노베이션 캠프/3주차_알고리즘 2023. 6. 21. 14:19
문제 https://school.programmers.co.kr/learn/courses/30/lessons/1845 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 문제 풀이 function solution(nums) { // 1) 주어진 nums에서 중복된 값 제외한 새로운 배열 생성 let temp = [...new Set(nums)]; // 2) nums의 길이를 가져와 2로 나눈 값 저장 let len = nums.length / 2; // 3) nums에서 중복 제거하여 만든 배열의 길이 저장 let templen = temp.length; //..
-
[JS] 소수 찾기이노베이션 캠프/3주차_알고리즘 2023. 6. 21. 13:27
문제 https://school.programmers.co.kr/learn/courses/30/lessons/12921 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 문제 풀이 풀이1. 짝수 값 포함되어 있을 때 function isPrime(num) { // 짝수에 대한 처리 if (num % 2 === 0) { return num === 2 ? true : false; } // 짝수에 대한 처리 for (let i=3; i
-
[JS] 나머지가 1이 되는 수 찾기이노베이션 캠프/3주차_알고리즘 2023. 6. 21. 11:52
문제 https://school.programmers.co.kr/learn/courses/30/lessons/87389 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 문제 풀이 풀이1. 가장 큰 수부터 확인 function solution(n) { let x = n; // 1) 나눈 나머지가 1이 되도록 하는 가장 작은 자연수 값 저정할 변수 선언 및 할당 // 2) for문 이용하여 주어진 n부터 -1씩 뺀 값에 접근 for (let i=n; i > 0; i--) { if (n % i !== 1) continue; // 2-1) 나머지 값이 1이 아니면..