본문 바로가기

알고리즘

(56)
[programmers] 숫자 문자열과 영단어 https://programmers.co.kr/skill_checks/411665?challenge_id=7777 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr https://school.programmers.co.kr/learn/courses/30/lessons/81301 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr return 에서 변수를 두개를 전달하지 못한다 function solution(s) ..
[programmers] 최솟값 만들기 https://school.programmers.co.kr/learn/courses/30/lessons/12941?language=javascript 이 문제의 경우 두가지를 생각해봤다. 1. 오름차순 배열a, 내림차순 배열b를 각각 곱해서 더한다. 2. 모든 경우의 수를 더해서 그중에서 최소 값을 구한다. 2번을 구현해보고 싶었으나 쉽지 않았다. function solution(A,B){ var answer = []; for(let i=0; i
[programmers] 같은 숫자는 싫어 https://school.programmers.co.kr/learn/courses/30/lessons/12906?language=javascript 핵심: 이전과 다른 값이 등장하면 배열에 값을 추가한다. 연속이라는 것이 중요했다. 처음 무조건 넣고 이전의 값과 다르면 answer에 값을 추가하면 된다. function solution(arr) { let prev =0; let answer = []; // console.log(arr) arr.forEach((ele, index, arr)=>{ console.log(ele, index); if(index==0){ prev = ele; answer.push(ele); } else{ if(prev!=ele) answer.push(ele); prev = el..
프로그래머스 직사각형 나머지 한 점 https://school.programmers.co.kr/learn/courses/18/lessons/1878 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 핵심: 사각형은 숫자가 2번씩 겹친다. 겹치지 않는 값을 x,y에 넣어주면 된다 function solution(v) { let left = new Map(); let right = new Map(); let answer = []; // let result = v.map((ele)=>{ // map.has(ele[0]){ // } // }) for(let [key, value] of v){ // c..
https://leetcode.com/problems/binary-search/submissions/ binary Search 1) inner class call //기준 클래스 //클래스 내부 메서드를 호출한다. public class BinarySearch { // https://leetcode.com/problems/binary-search/ //main 메서드 public static void main(String[] args) { int[] num = {-1,0,3,5,9,12}; // int target = 9;//4 int target = 2;//-1 int result = search(num,target); System.out.println(result); } // static을 메서드에 달아줘야 main에서 호출이 가능하다 // 클래스 내부 메서드는 객체를 생성하지 않고 사용 가능 pub..
leetcode.com/problems/first-bad-version/ https://leetcode.com/problems/first-bad-version/ First Bad Version - 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 /* The isBadVersion API is defined in the parent class VersionControl. boolean isBadVersion(int version); */ public class Solution extends VersionControl { public in..
[프로그래머스] 크레인 인형 뽑기 게임 https://programmers.co.kr/learn/courses/30/lessons/64061 코딩테스트 연습 - 크레인 인형뽑기 게임 [[0,0,0,0,0],[0,0,1,0,3],[0,2,5,0,1],[4,2,4,4,2],[3,5,1,3,1]] [1,5,3,5,1,2,1,4] 4 programmers.co.kr
[프로그래머스] 서울에서 김서방 찾기 // https://programmers.co.kr/learn/courses/30/lessons/12919 //seoul은 길이 1 이상, 1000 이하인 배열입니다. //seoul의 원소는 길이 1 이상, 20 이하인 문자열입니다. let seoul = ["Jane", "Kim"]; let result = solution(seoul); console.log(result); let result2 = findKim(seoul); console.log(result2); // include boolean 반환 //`The word "${word}" ${sentence.includes(word) ? 'is' : 'is not'} in the sentence` // 문자열.match(찾을 단어) //indexOf..