본문 바로가기

Research/problems10

프로그래머스_lv0_외계어사전 문제 문제 설명 PROGRAMMERS-962 행성에 불시착한 우주비행사 머쓱이는 외계행성의 언어를 공부하려고 합니다. 알파벳이 담긴 배열 spell과 외계어 사전 dic이 매개변수로 주어집니다. spell에 담긴 알파벳을 한번씩만 모두 사용한 단어가 dic에 존재한다면 1, 존재하지 않는다면 2를 return하도록 solution 함수를 완성해주세요. spell, dic 둘 다 어레이 형태의 매개변수다. spell에 있는 알파벳의 조합한 단어가 dict 어레이에 있는지 확인하고, 1 또는 2를 리턴하면 된다. 0, 1이 아니라 1, 2이다. 제한사항 spell과 dic의 원소는 알파벳 소문자로만 이루어져있습니다. 알파벳 대문자, 숫자는 신경안써도 된다 2 ≤ spell의 크기 ≤ 10 2~10개이다. 1.. 2022. 11. 28.
프로그래머스_lv0_구슬을 나누는 경우의 수 문제 생각 해결 나의 해결 while문으로 0이 될때까지의 수를 곱해주는 방식으로 취했다. function solution(balls, share) { function getPossible(input) { let result = 1 while(input) { result *= input; input--; } return result } const allPossibles = getPossible(balls) / ((getPossible(balls - share)) * getPossible(share)) return Math.round(allPossibles) } console.log(solution(30, 15)) 다른 사람 풀이 다른 사람 풀이를 보니 이를 재귀함수로 사용할 수 있음을 알았다. const.. 2022. 11. 26.
프로그래머스_lv0_문자열 계산하기 문제 생각 function solution(my_string) { var answer = my_string.split(' ') var [x, y] = [Number(answer[0]), Number(answer[2])] var operator = answer[1] var result = operator === "+"? x + y : x - y return result; } 코드 실행에서는 정상적으로 작동하는데 제출하려니 테스트에서 실패한다. 어떤 분이 질문하기에 적어둔 글을 보니 2 +2 + 2 와 같이 연산자가 1개 이상일 수도 있다고 한다. 생각해보니 2+2 처럼 문자열이 된 수식이라고 해서 꼭 연산을 1번만 하라는 것은 아니긴 하다. 그래서 나는 1 + 2 + 3일 경우 +2, +3을 짝으로 보고,.. 2022. 11. 26.
LeetCode_283_Move Zeros date: 2022-11-24level: easy Problem My Solution /** * @param {number[]} nums * @return {void} Do not return anything, modify nums in-place instead. */ var moveZeroes = function(nums) { let count = 0; let chance = nums.length while (chance) { if(nums[0] === 0) { nums.shift(); count++ } else { nums[nums.length] = nums[0] nums.shift(); } chance-- } while(count) { nums.push(0); count-- } return nums.. 2022. 11. 24.