## 과제 : 프로그래머스 문제 풀기 1. [중복된 문자 제거](https://school.programmers.co.kr/learn/courses/30/lessons/120888) 2. [두 개 뽑아서 더하기](https://school.programmers.co.kr/learn/courses/30/lessons/68644) ## 과제 : 프로그래머스 문제 풀기 모범 답안 1. 중복된 문자 제거 ```java class Solution { public String solution(String my_string) { String answer = ""; boolean[] check = new boolean[128]; for (int i = 0; i < my_string.length(); ++i) { char c = my_string.charAt(i); if (!check[c]) { answer += c; check[c] = true; } } return answer; } } ``` 2. 두 개 뽑아서 더하기 ```java class Solution { public int[] solution(int[] numbers) { int n = numbers.length; int[] temp = new int[n * (n - 1) / 2]; int idx = 0; // 가능한 모든 조합의 합을 계산 for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { temp[idx++] = numbers[i] + numbers[j]; } } // 배열 정렬 bubbleSort(temp); // 중복 제거 int count = 0; for (int i = 1; i < temp.length; i++) { if (temp[i] != temp[i - 1]) { count++; } } // 결과 배열 생성 int[] answer = new int[count + 1]; answer[0] = temp[0]; int answerIdx = 1; for (int i = 1; i < temp.length; i++) { if (temp[i] != temp[i - 1]) { answer[answerIdx++] = temp[i]; } } return answer; } public static void bubbleSort(int[] array) { int n = array.length; for (int i = 0; i < n - 1; i++) { for (int j = 0; j < n - i - 1; j++) { if (array[j] > array[j + 1]) { int temp = array[j]; array[j] = array[j + 1]; array[j + 1] = temp; } } } } } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up