코딩테스트-알고리즘/도전

2023.12.21 - 10문제

닉네임생각즁 2023. 12. 21. 06:42

 

문자 리스트를 문자열로 변환하기

https://school.programmers.co.kr/learn/courses/30/lessons/181941

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

class Solution {
    public String solution(String[] arr) {
        String answer = "";
        
        for(int i=0; i<arr.length; i++) {   
            answer+=arr[i];
        }        
        return answer;
    }
}

 

다른 사람 풀이

 return String.join("", arr);

배열을 하나로 합쳐주거나 여러 문자열을 하나로 합쳐줌 ""속 내용이 붙일때 사이에 들어가는 내용

for(String a : arr) {
            answer += a;
        }

for each문이 더 간단!!

 

 

문자열 곱하기

https://school.programmers.co.kr/learn/courses/30/lessons/181940

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

class Solution {
    public String solution(String my_string, int k) {
        String answer = "";
        int i = 0;
        
        while (i < k) { 
            answer += my_string ;
            i++;
        }
        return answer;
    }
}

 

다른 사람 풀이

return my_string.repeat(k);

맞다,,! 어제 풀 때 본건데 또 까먹음

 

 

더 크게 합치기

https://school.programmers.co.kr/learn/courses/30/lessons/181939

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

class Solution {
    public int solution(int a, int b) {
        int answer = 0;
        
        String str1 = "" + a + b;
        int num1 = Integer.parseInt(str1);
        String str2 = "" + b + a;
        int num2 = Integer.parseInt(str2);
        
        if (num1 >= num2) {
            answer = num1;
        } else {
            answer = num2;
        }
        
        return answer;
    }
}

 

 

두 수의 연산값 비교하기

https://school.programmers.co.kr/learn/courses/30/lessons/181938

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

class Solution {
    public int solution(int a, int b) {
        int answer = 0;
        
        String str = "" + a + b;
        int num1 = Integer.parseInt(str);
        int num2 = 2 * a * b;
        
        if (num1>=num2){
            answer = num1;
        } else {
            answer = num2;
        }
        
        return answer;
    }
}

 

 

n의 배수

https://school.programmers.co.kr/learn/courses/30/lessons/181937

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

class Solution {
    public int solution(int num, int n) {
        int answer = 0;
        
        if(num%n==0) {
            answer = 1;
        } else {
            answer = 0;
        }
        return answer;
    }
}

 

 

공배수

https://school.programmers.co.kr/learn/courses/30/lessons/181936

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

class Solution {
    public int solution(int number, int n, int m) {
        int answer = number % n == 0 && number % m == 0 ? 1 : 0;
        return answer;
    }
}

 

 

 

홀짝에 따라 다른 값 반환하기

https://school.programmers.co.kr/learn/courses/30/lessons/181935

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

class Solution {
    public int solution(int n) {
        int answer = 0;
        
        if(n%2==1){
            for(int i=1; i<=n; i+=2){
                answer+=i;
            }
        } else {
            for(int i=2; i<=n; i+=2) {
                answer+=Math.pow(i,2);
            }
        }
        
        return answer;
    }
}

 

 

조건 문자열

https://school.programmers.co.kr/learn/courses/30/lessons/181934

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

class Solution {
    public int solution(String ineq, String eq, int n, int m) {
        int answer = 0;
        
        if(ineq.equals(">")) {
            if(eq.equals("=")) {
                answer = n >= m ? 1 : 0;
            } else {
                answer = n > m ? 1 : 0;
            }
        }
        
        if(ineq.equals("<")) {
            if(eq.equals("=")) {
                answer = n <= m ? 1 : 0;
            } else {
                answer = n < m ? 1 : 0;
            }
        }        
        
        return answer;
    }
}

 

 

부분 문자열인지 확인하기

https://school.programmers.co.kr/learn/courses/30/lessons/181843

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

class Solution {
    public int solution(String my_string, String target) {
        int answer = 0;
        
        answer = my_string.contains(target) ? 1 : 0;
        
        return answer;
    }
}

 

 

배열 조각하기 조각하

https://school.programmers.co.kr/learn/courses/30/lessons/181893?language=java

 
 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

import java.util.Arrays;

class Solution {
    public int[] solution(int[] arr, int[] query) {
        int[] answer = {};
        
        for(int i=0; i<query.length; i++) {
            if(i % 2 == 0) {
                arr = Arrays.copyOfRange(arr,0,query[i]+1);
            } else {
                arr = Arrays.copyOfRange(arr,query[i],arr.length);
            }
        }
        
        answer = Arrays.copyOf(arr, arr.length);
        
        return answer;
    }
}

'코딩테스트-알고리즘 > 도전' 카테고리의 다른 글

2023.12.25 - 6문제  (0) 2023.12.25
2023.12.24 - 4문제  (0) 2023.12.24
2023.12.23 - 9문제  (1) 2023.12.23
2023.12.20 - 12문제  (1) 2023.12.20
12월 31일까지 도전  (0) 2023.12.20