Post

[Programmers] #181941 - 문자 리스트를 문자열로 변환하기 [Java][C++][Python]

배열에 담긴 문자들을 순서대로 이어 붙여 하나의 문자열로 만드는 문제.

[Programmers] #181941 - 문자 리스트를 문자열로 변환하기 [Java][C++][Python]

문제 링크


1. 아이디어

배열 arr에 담긴 문자들을 순서대로 이어 붙이면 정답이 되는 문제다. 배열을 앞에서부터 순회하며 각 원소를 하나의 문자열에 누적하면 된다.


2. 복잡도

접근시간공간
풀이$O(N)$$O(N)$

($N$ = 배열 arr의 길이)


3. 코드

풀이 [Java][C++][Python]

1
2
3
4
5
class Solution {
    public String solution(String[] arr) {
        return String.join("", arr);
    }
}
1
2
3
4
5
6
7
8
#include <bits/stdc++.h>
using namespace std;

string solution(vector<string> arr) {
    string s;
    for (auto& x : arr) s += x;
    return s;
}
1
2
def solution(arr):
    return "".join(arr)

This post is licensed under CC BY 4.0 by the author.