본문 바로가기

Programmers

(24)
[프로그래머스] 올바른 괄호 (JS) 문제 https://school.programmers.co.kr/learn/courses/30/lessons/12909 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 코드 내 풀이 function solution(s){ const stack = []; if(s.length%2===1) return false; for (e of s){ if(stack.length===0 && e===')') return false; if(stack.length!==0 && stack[stack.length-1]==='(' && e===')') stack.pop(); els..
[프로그래머스] 기능 개발 (JS) 문제 https://school.programmers.co.kr/learn/courses/30/lessons/42586 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 코드 내 풀이 function solution(progresses, speeds) { const answer = []; let idx=0; while(idx!==progresses.length){ for(let i=0; i=100){ let cnt=1; for(let i=idx+1; i
[프로그래머스] 같은 숫자는 싫어 (JS) 문제 https://school.programmers.co.kr/learn/courses/30/lessons/12906 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 코드 function solution(arr){ const answer = []; arr.forEach(a => { if(answer.length===0 || answer[answer.length-1]!==a) answer.push(a); }) return answer; } 정리 JS에서 배열에 마지막 원소를 접근하고 싶을 때 answer[answer.length-1] answer[-1]로는..
[프로그래머스] 가장 큰 수 (JS) - sort 문제 https://school.programmers.co.kr/learn/courses/30/lessons/42746 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 코드 function solution(numbers) { const answer = numbers.map(n => String(n)).sort((a,b) => (b+a)-(a+b)).join(''); return answer[0]==='0' ? '0':answer; } 정리 string으로 대소 비교를 하기 위해 map을 사용해 원소를 string type으로 변경해준다. const answ..
[프로그래머스] K번째수 (JS) - sort 문제 https://school.programmers.co.kr/learn/courses/30/lessons/42748 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 코드 function solution(array, commands) { const answer = []; const length = commands.length; for (let command of commands){ const [i,j,k] = command; const temp = array.slice(i-1,j) temp.sort((a,b)=>(a-b)) answer.push(temp[..
[프로그래머스] 소수 찾기 (JS) - 완전탐색, DFS 문제 https://school.programmers.co.kr/learn/courses/30/lessons/42839 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 코드 function solution(numbers){ const answer = []; const nums = numbers.split(''); const length = nums.length; const isVisited = Array.from({length:length}, ()=>false); const arr = Array.from({length:length}, ()=>0); func..
[프로그래머스] 모의고사 (JS) - 완전탐색 문제 https://school.programmers.co.kr/learn/courses/30/lessons/42840 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 코드 function solution(answers) { const answer = []; const user1 = [1,2,3,4,5]; const user2 = [2,1,2,3,2,4,2,5]; const user3 = [3,3,1,1,2,2,4,4,5,5]; const user1Length = user1.length; const user2Length = user2.length; cons..
[프로그래머스] 신고 결과 받기 (C++, JS) 문제 https://school.programmers.co.kr/learn/courses/30/lessons/92334 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 코드 C++ #include #include #include #include using namespace std; map reportingIds; map reportedNums; vector solution(vector id_list, vector report, int k) { vector answer; sort(report.begin(), report.end()); report.erase(..