본문 바로가기

today I learned/algorithm

(3)
[DFS] 타겟넘버 문제 https://school.programmers.co.kr/learn/courses/30/lessons/43165 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 풀이 class Solution { int cnt = 0; public int solution(int[] numbers, int target) { int answer = 0; dfs(numbers, target, 0, 0); answer = cnt; return answer; } public void dfs(int[] numbers, int target, int depth, int resul..
[해시] 전화번호 목록 문제 https://school.programmers.co.kr/learn/courses/30/lessons/42577 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 풀이 import java.util.*; import java.util.stream.Collectors; class Solution { public boolean solution(String[] phone_book) { List sortedPhones = Arrays.stream(phone_book) .sorted() .collect(Collectors.toList()); for(int i ..
[해시] 폰켄몬 문제 https://school.programmers.co.kr/learn/courses/30/lessons/1845 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 풀이 import java.util.*; import java.util.stream.Collectors; class Solution { public int solution(int[] nums) { /* 1) 배열의 distinct 수를 구함 2-1) 그 수가 N/2 이상이면 N/2출력 2-2) 그 수가 N/2 미만이면 distinct의 count 출력 */ int nDivTwo = nums.l..