본문 바로가기

반응형

👩🏻‍💻 기술면접/알고리즘

(13)
[프로그래머스] JAVA K번째 수 Level 1. 💡 나의 풀이 import java.util.*; class Solution { public int[] solution(int[] array, int[][] commands) { int[] answer = new int[commands.length]; for(int i = 0; i > Arrays.copyOfRange(배열, 시작인덱스, 마지막인덱스)를 사용하여 배열을 slicing 해준다. 시..
[프로그래머스] JAVA 완주하지 못한 선수 Level 1 💡 나의 풀이 Hash를 사용하지 않았을 때 나의 풀이 (Hash를 사용한 코드보다 시간복잡도 큼) 처음에 HashMap을 썼다가 사용이 미숙하여 패스..List 썼다가 이중 for문 썼다가 난리ㅠ 저번 스터디 때 친구가 Arrays.sort로 정렬한 뒤 완주한 선수 지워나가는 것에서 힌트를 얻어서 풀었다. participant와 completion이 정렬되어 있기 때문에 계속 비교해서 값이 같지 않은 것이 나왔을 때 participant[i]를 return하면 완주하지 못한 선수가 나온다. import java.util.*; class Solution { public String solution(String[] participant, String[] completion) { String answer =..
[프로그래머스] JAVA 비밀지도(카카오 블라인드) Level 1. 💡 나의 풀이 10진수를 2진수로 변환하는 함수인 Integer.toBinaryString(num)과 replace 함수를 사용하여 풀이 비트연산자 "|"를 사용하여 먼저 수행 후 "#" 또는 " "으로 대체하여 출력 | -> 둘 중 하나라도 1이면 1, 아니면 0 (OR) & -> 둘 중 모두 1이면 1, 아니면 0 (AND) ^ -> 두 비트가 다를 때 1 출력 (XOR) ~ -> 비트 전환 연산자 / 1이면 0, 0이면 1로 전환 import java.util.*; class Solution { public String[] solution(int n, int[] arr1, int[] arr2) { String[] answer = new String[n]; for(int i = 0; i < n; i+..
[프로그래머스] JAVA 행렬의 덧셈 Level 1. 💡 나의 풀이 class Solution { public int[][] solution(int[][] arr1, int[][] arr2) { int[][] answer = new int[arr1.length][arr1[0].length]; for(int i = 0; i < arr1.length; i++){ for(int j = 0; j < arr1[i].length; j++){ answer[i][j] = arr1[i][j]+arr2[i][j]; } } return answer; } }
[프로그래머스] JAVA 소수 찾기 Level 1 💡 나의 풀이(효율성에서 시간복잡도 큼) class Solution { public int solution(int n) { int answer = 0; for(int i = 2; i
[프로그래머스] Java 문자열 내 마음대로 정렬하기 Level 1 💡 나의 풀이 어려웠다..n번째 단어를 각 단어 앞에 붙여주고 오름차순 정렬해준 뒤 붙여놨던 n번째 단어를 substring으로 잘라내어 주었다. 검색해보니까 Comparator를 사용하던데 그러면 메소드 추가에 할게 많길래 나중에 더 공부해보는걸로... 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 import java.util.*; class Solution { public String[] solution(String[] strings, int n) { String[] answer = {}; List arr = new ArrayList(); //charAt(n)으로 n번째 단어 + i번째 단어를 붙여준다. for(int i = 0; i
[프로그래머스] Java 나누어 떨어지는 숫자 배열 Level 1 💡 나의 풀이 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 import java.util.*; class Solution { public int[] solution(int[] arr, int divisor) { int[] answer = {}; ArrayList array = new ArrayList(); for(int i = 0; i
[프로그래머스] Java 모의고사 Level 1 💡 나의 풀이 채점 결과 정확성: 100.0 합계: 100.0 / 100.0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 import java.util.*; class Solution { public int[] solution(int[] answers) { int[] answer = {}; int first[] = {1,2,3,4,5}; //규칙 반복(이하 동일) int second[] = {2,1,2,3,2,4,2,5}; int third[] = {3,3,1,1,2,2,4,4,5,5}; int all[] = new int[3]; //3명 비교 for(int i = 0..

반응형