본문 바로가기

알고리즘/문제풀이7

10주차 알고리즘 풀이 217. Contains Duplicate 코드 const containsDuplicate = (nums) => { const set = new Set(nums); return set.size !== nums.length; }; 문제풀이 1. 중복하지 못하게 set에 배열을 넣어준다. 2. 중복값이 있다면 set의 크기와 기존배열의 크기가 다르다. 이것을 사용해서 boolean값을 반환함 Contains Duplicate - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcod.. 2021. 10. 23.
이진트리) Maximum Depth of Binary Tree [js] Maximum Depth of Binary Tree - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 //이런식으로 재귀 코드를 작성하고 생각하는 것이 더 쉽기 때문에 핸들러 함수를 사용 var maxDepth = function(root) { //깊이의 정의 때문에 숫자/깊이 값 1에서 시작 return maxDepthHandler(root,1) }.. 2021. 8. 27.
프로그래머스 모의고사 javascript 문제링크 https://programmers.co.kr/learn/courses/30/lessons/42840 코딩테스트 연습 - 모의고사 수포자는 수학을 포기한 사람의 준말입니다. 수포자 삼인방은 모의고사에 수학 문제를 전부 찍으려 합니다. 수포자는 1번 문제부터 마지막 문제까지 다음과 같이 찍습니다. 1번 수포자가 찍는 programmers.co.kr 코드 function solution(answers) { let answer = []; let supo = [ [1, 2, 3, 4, 5], [2, 1, 2, 3, 2, 4, 2, 5], [3, 3, 1, 1, 2, 2, 4, 4, 5, 5], ]; let score = []; for (let i = 0; i < supo.length; i++) { le.. 2021. 8. 21.
프로그래머스) K번째 수 Javascript https://programmers.co.kr/learn/courses/30/lessons/42748 코딩테스트 연습 - K번째수 [1, 5, 2, 6, 3, 7, 4] [[2, 5, 3], [4, 4, 1], [1, 7, 3]] [5, 6, 3] programmers.co.kr function solution(array, commands) { const answer = []; commands.forEach(command => { const arrayCommand = array.slice(command[0]-1, command[1]); arrayCommand.sort((a,b) => a - b); answer.push(arrayCommand[command[2]-1]); }) return answer; }.. 2021. 8. 20.