코딩 테스트 (Java)/코딩 기초 트레이닝 (프로그래머스)

181942. 문자열 섞기

가지코딩 2025. 4. 1. 14:22

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

 

프로그래머스

SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr


문제

길이가 같은 두 문자열 str1str2가 주어집니다.

두 문자열의 각 문자가 앞에서부터 서로 번갈아가면서 한 번씩 등장하는 문자열을 만들어 return 하는 solution 함수를 완성해 주세요.

 

제한사항

  • 1 ≤ str1의 길이 = str2의 길이 ≤ 10
    • str1str2는 알파벳 소문자로 이루어진 문자열입니다.

 

입출력 예

str1 str2 result
"aaaaa" "bbbbb" "ababababab"

 


풀이

class Solution {
    public String solution(String str1, String str2) {
        String answer = "";
        
        for(int i=0; i<str1.length(); i++){
            answer += "" + str1.charAt(i) + str2.charAt(i);
        }
        return answer;
    }
}

 

 

 


GitHub: https://github.com/gajicoding/coding_test/edit/main/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4/0/181942.%E2%80%85%EB%AC%B8%EC%9E%90%EC%97%B4%E2%80%85%EC%84%9E%EA%B8%B0

 

coding_test/프로그래머스/0/181942. 문자열 섞기 at main · gajicoding/coding_test

This is an auto push repository for Baekjoon Online Judge created with [BaekjoonHub](https://github.com/BaekjoonHub/BaekjoonHub). - gajicoding/coding_test

github.com


출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/challenges

 

코딩테스트 연습 | 프로그래머스 스쿨

개발자 취업의 필수 관문 코딩테스트를 철저하게 연습하고 대비할 수 있는 문제를 총망라! 프로그래머스에서 선발한 문제로 유형을 파악하고 실력을 업그레이드해 보세요!

school.programmers.co.kr