반응형
알고리즘/프로그래머스2023. 7. 23. 23:12프로그래머스 Level 2. 타겟 넘버 (Java)

문제 링크 타겟 넘버 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 풀이 코드 class Solution { public int solution(int[] numbers, int target) { int answer = dfs(0, 0, numbers, target); return answer; } private int dfs(int depth, int sum, int[] numbers, int target) { if(depth == numbers.length) { if (sum == target) return 1; else return 0; } retu..

알고리즘/프로그래머스2023. 7. 20. 00:51프로그래머스 Level 2. 올바른 괄호 (Java)

문제 링크 올바른 괄호 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 풀이 코드 import java.util.*; class Solution { boolean solution(String s) { boolean answer = true; Stack stack = new Stack(); for(char x : s.toCharArray()) { if(x == '(') stack.push(x); else { if(!stack.isEmpty()) { stack.pop(); } else { return false; } } } if(stack.isEmpty()) ..

알고리즘/프로그래머스2023. 7. 20. 00:48프로그래머스 Level 2. 시소 짝꿍 (Java)

문제 링크 시소 짝꿍 풀이 코드 import java.util.*; class Solution { public long solution(int[] weights) { long answer = 0; // 무게배열의 길이는 10만까지 이지만, 무게는 100부터 1000까지만 존재하므로 중복을 제거한다면 최대 길이는 900이므로 중복을 제거하여 map에 담아준다. // key는 무게, value는 사람 수 Map map = new HashMap(); for(int i=0; i

알고리즘/프로그래머스2023. 7. 20. 00:43프로그래머스 Level 2. 기능 개발 (Java)

문제링크 기능 개발 풀이 코드 import java.util.*; class Solution { public int[] solution(int[] progresses, int[] speeds) { //map으로 배포되는 기능들 중복카운팅 하기.(배포되는 일자, 배포되는 기능 횟수) Map map = new LinkedHashMap(); //탐색 배열 길이 뽑기 int len = progresses.length; int[] arr = new int[len]; // 작업들의 남은 일 수 계산하여 arr에 넣기 int beforeWorkDay = 0; for(int i=0; i workDay) workDay = beforeWorkDay; map.put(workDay, map.getOrDefault(workDa..

반응형
image
loading