본문 바로가기

알고리즘117

[백준] 18870번 좌표 압축 #Java 1. 복사 배열을 만든다. 2. 순회하면서 값과 인덱스를 저장하는 해시맵을 구성한다. 3. 해당 값을 꺼내 출력한다. import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); HashMap hashMap = new HashMap(); int n = Integer.parseInt(br.readLine()); int [] answer = new int [n]; StringTokenizer st = new StringTokenize.. 2022. 5. 22.
[프로그래머스] 약수의 개수와 덧셈 #Java import java.io.IOException; import java.util.*; class Main { public static void main(String[] args) throws IOException { int l = 13; int r = 17; System.out.println(solution(l,r)); } public static int solution(int left, int right) { int answer = 0; for (int i = left; i 2022. 5. 20.
[프로그래머스] 없는 숫자 더하기 #Java import java.io.IOException; import java.util.*; class Main { public static void main(String[] args) throws IOException { int [] arr = {1,2,3,4,6,7,8,0}; System.out.println(solution(arr)); System.out.println(solution2(arr)); } public static int solution(int[] numbers) { int answer = 0; int [] ans = new int[10]; for (int i = 0; i < numbers.length; i++) { ans[numbers[i]]++; } for (int i = 0; i < an.. 2022. 5. 20.
[프로그래머스] 신고 결과 받기 #Java 개선 전 코드(정답이긴 함) import java.io.IOException; import java.util.*; class Main { public static void main(String[] args) throws IOException { String [] id_list = {"muzi", "frodo", "apeach", "neo"}; String [] report = {"muzi frodo","apeach frodo","frodo neo","muzi neo","apeach muzi"}; int k = 2; for (int i : solution(id_list, report, k)) { System.out.printf("%d ", i); } } public static int [] solution.. 2022. 5. 20.