[프로그래머스] 평행 (직선의 평행 조건)
·
Algorithm
https://school.programmers.co.kr/learn/courses/30/lessons/120875 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 문제 푼 코드 package programmers.pr2023.Lv0.March; public class Lv0_평행_20230315 { public static void main(String[] args) { int[][] dots = {{1, 4}, {9, 2}, {3, 8}, {11, 6}}; Solution s = new Solution(); System.out.println(s.solu..
[프로그래머스] 연속된 수의 합(등차수열의 합)
·
Algorithm
https://school.programmers.co.kr/learn/courses/30/lessons/120923 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 문제 푼 코드 public class Lv0_연속된수의합_20230307 { class Solution { public int[] solution(int num, int total) { int[] answer = new int[num]; int i = 0; while(true) { int tempI = i; int cnt = 0; int sum = 0; int j = 0; // 배열의 인덱스 w..
[프로그래머스] 유한소수 판별하기(유클리드호제법, 소인수분해)
·
Algorithm
https://school.programmers.co.kr/learn/courses/30/lessons/120878 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 문제 푼 코드 package programmers.pr2023.Lv0.February; import java.util.HashSet; import java.util.Iterator; public class Lv0_유한소수판별하기_20230227 { class Solution { public int solution(int a, int b) { // 유한소수라면 1, 무한소수라면 2(유한소수 조건 ..
[프로그래머스] 문자열 정렬하기(1)
·
Algorithm
https://school.programmers.co.kr/learn/courses/30/lessons/120850 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 문제 푼 코드 해당 문제를 풀기 위해서 숫자가 담긴 String 배열을 만들고 이중 for 문을 돌면서 숫자가 맞으면 ArrayList에 담고 break를 걸었다. my_string 크기 만큼 다 돈 뒤에 ArrayList를 오름차순으로 정렬하고 : list.sort(Comparator.naturalOrder() ArrayList를 int 배열인 answer에 담아주었다 : list.stream..
[프로그래머스] 분수의 덧셈 / 유클리드 호제법(최대공약수 구하기)
·
Algorithm
https://school.programmers.co.kr/learn/courses/30/lessons/120808# 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 문제 푼 코드 분수의 덧셈을 풀기 위해서 처음에는 더 큰 분모를 찾고 큰분모와 작은분모의 나머지가 0이라면 덧셈 계산을 하려고 했다. 그런데 나머지가 0이 안될 때는 어떻게 덧셈을 해야하는지 막혀버렸다..;; 약수를 구해야하는 상황인데 내가 구현한 코드로는 더욱 복잡해지는 상황. 그래서 일단 약수를 구하기 전에 분수의 덧셈을 하고 그 다음에 최대공약수를 구해서 덧셈으로 구한 분자와 분모에 최대..
[프로그래머스] 단어 변환 / DFS/BFS(그래프탐색)
·
Algorithm
https://school.programmers.co.kr/learn/courses/30/lessons/43163 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 코드 import java.util.*; class Solution { public int solution(String begin, String target, String[] words) { int answer = 0; int[] visited = new int[words.length]; Queue q = new LinkedList(); int cnt; for (int i = 0; i < word..
[프로그래머스] 완주하지 못한 선수 / Hash
·
Algorithm
https://school.programmers.co.kr/learn/courses/30/lessons/42576 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 코드 public String solution(String[] participant, String[] completion) { String answer = ""; HashMap map = new HashMap(); // 참가한 선수를 map에 넣기 만약 같은 이름의 선수가 있다면 2,3,4 이런식으로 숫자가 계속 증가됨 for (String player : participant) { map.put..
[백준] 14425번 문자열 집합 / Hash
·
Algorithm
https://www.acmicpc.net/problem/14425 14425번: 문자열 집합 첫째 줄에 문자열의 개수 N과 M (1 ≤ N ≤ 10,000, 1 ≤ M ≤ 10,000)이 주어진다. 다음 N개의 줄에는 집합 S에 포함되어 있는 문자열들이 주어진다. 다음 M개의 줄에는 검사해야 하는 문자열들이 주어 www.acmicpc.net 코드 package baekjoon; import java.util.HashMap; import java.util.Scanner; public class 문자열집합_14425 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int answer = 0; int N = sc...
[프로그래머스] 위장 / Hash
·
Algorithm
https://school.programmers.co.kr/learn/courses/30/lessons/42578 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 코드 import java.util.HashMap; class Solution { public int solution(String[][] clothes) { int answer = 1; // 종류별로 곱할 예정이라 1로 할당 HashMap map = new HashMap(); // 경우의 수는 종류+1 이다. 0인 경우도 포함해야하기 때문에! // 조건에 최소 한 개는 입기 때문에 여기서 -1도 ..