본문 바로가기

with my rubber duck/codingTest44

[프로그래머스] K번째변수 풀어보기 import java.util.Arrays; class Solution { public int[] solution(int[] array, int[][] commands) { int[] answer = new int[commands.length]; //커맨드 배열의 크기만큼 돌아감 for(int i = 0;i arr[j]){ int temp = arr[k]; arr[k] = arr[j]; arr[j] = temp; } } } //인덱스에 있는 값을 가져와서 정답 배열에 넣는다 answer[i]=arr[(commands[i][2])-1]; } return answer; } } 겸사겸사 정렬 알고리즘도 복습했다. 인텔리제이만 쓰다가 갑자기 아무 기능도 없는 IDE 쓰려니 너무 .... 불편하다ㅋㅋ... 앞으로.. 2022. 6. 3.
[프로그래머스] 수박수박수박수박수박수? 나: class Solution { public String solution(int n) { String answer = ""; label: while(true){ if(n!=0){ answer+="수"; n--; }else{ break label; } if(n!=0){ answer+="박"; n--; }else{ break label; } } return answer; } } 그지같지만 단순한 코드 ㅋㅋㅋㅋㅋㅋㅋㅋ 풀면된거아님?ㅎ 그치만 너무 중복된게 많아서 다시 좀 더 생각해봤당 class Solution { public String solution(int n) { String answer = ""; int num = n-n; while(num!=n){ num++; answer+= num%2==1?".. 2022. 6. 2.
[프로그래머스] 가운데 글자 가져오기 복습을 위한 기록 내가 한거 class Solution { public String solution(String s) { int length = s.length(); int lengthHalf =length/2; return length%2==1 ? s.substring(lengthHalf,lengthHalf+1) :s.substring(lengthHalf-1,lengthHalf+1); } } 좋은 답: class StringExercise{ String getMiddle(String word){ return word.substring((word.length()-1) / 2, word.length()/2 + 1); } 출처 : https://programmers.co.kr/learn/courses/30/.. 2022. 6. 2.
백준 2442 자바 문제 답 코드 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc= new Scanner(System.in); int num = sc.nextInt(); for(int i = 1;ii;k--) { System.out.print(" "); } for(int j = 0;j< 2*i-1;j++){ System.out.print("*"); } System.out.println(); } } } 2022. 4. 18.
백준 2441 별 찍기 - 4 자바 문제 내 코드 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); for(int i = 0;i 2022. 4. 17.
백준 자바 별 찍기 - 3 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); for(int i = 0;i=i;j--) { System.out.print("*"); } System.out.println(); } } } 짱쉽네~ 2022. 4. 15.
728x90