[프로그래머스 | C# | Lv.0] 글자 이어 붙여 문자열 만들기

728x90

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

📝 나의 풀이

using System;

public class Solution {
    public int[] solution(int[] arr) {

        int index = 0;
        for(int i=0; i<arr.Length; i++){
            index +=arr[i];
        }
        
        int[] answer = new int[index];
        
        int answerIndex = 0;
        
        for(int i=0; i<arr.Length; i++){
            for(int j=0; j<arr[i]; j++){
                answer[answerIndex] = arr[i];
                answerIndex++;
            }
        }
        
        return answer;
    }
}
728x90