//구글콘솔 광고 추가가
728x90
반응형
옹알이 (1) 문제

내 코드
using System;

public class Solution {
    public int solution(string[] babbling) {
        int answer = 0;
        string[] ableTalk = {"aya", "ye", "woo", "ma"};
        for (int i = 0; i < babbling.Length; i++)
        {
            for (int j = 0; j < ableTalk.Length; j++)
            {
                babbling[i] = babbling[i].Replace(ableTalk[j], "H");
            }

            babbling[i] = babbling[i].Replace('H'.ToString(),"");
            if (babbling[i] == "") answer++;
        }        
        return answer;
    }
}
728x90
반응형
728x90
반응형
무작위로 K개의 수 뽑기 문제

 

내 코드
using System;
using System.Collections.Generic;
using System.Linq;
public class Solution {
    public int[] solution(int[] arr, int k) {
        var answer = new List<int>(arr).Distinct().ToList();
        var answerArr = new List<int>();
        for(int i =0; i < k; i++)
        {
            if(i < answer.Count)
                answerArr.Add(answer[i]);
            else
                answerArr.Add(-1);
        }
        return answerArr.ToArray();
    }
}

 

728x90
반응형
728x90
반응형
전국 대회 선발 고사 문제

 

내 코드
using System;
using System.Collections.Generic;
using System.Linq;
public class Solution {
    public int solution(int[] rank, bool[] attendance) {
        int answer = 0;
        Dictionary<int, int> dic = new Dictionary<int, int>();
        for (int i = 0; i < rank.Length; i++)
        {
            if (attendance[i])
                dic.Add(rank[i], i);
        }
        List<int> list = dic.Keys.ToList();
        list.Sort();
        answer = dic[list[0]] * 10000 + dic[list[1]] * 100 + dic[list[2]];
        return answer;
    }
}
728x90
반응형
728x90
반응형
수열과 구간 쿼리 2 문제

 

내 코드
using System;
using System.Collections.Generic;
using System.Linq;
public class Solution {
    public int[] solution(int[] arr, int[,] queries) {
        var answer = new List<int>();
        for (int i = 0; i < queries.GetLength(0); i++)
        {
            int min = arr.Max()+1;
            for (int j = queries[i, 0]; j <= queries[i, 1]; j++)
            {
                if (arr[j] > queries[i, 2] && arr[j]< min)
                    min = arr[j];
            }
            if (min == arr.Max() + 1) min = -1;
            answer.Add(min);
        }
        return answer.ToArray();
    }
}
728x90
반응형
728x90
반응형
코드 처리하기 문제

 

내 코드
using System;

public class Solution {
    public string solution(string code) {
        string answer = "";
        int mode =0;
        bool isOne =false;
        for(int i =0; i < code.Length; i++)
        {
            if(code[i] == '1')
            {
                if(isOne == false)
                {
                    isOne = true;
                    mode = 1;
                }
                else if(isOne == true)
                {
                    isOne = false;
                    mode = 0;
                }
            }
            if(mode == 0)
            {
                if(code[i] != '1')
                {
                    if(i %2 == 0)
                       answer += code[i]; 
                }
            }
            if(mode == 1)
            {
                if(code[i] != '1')
                {
                    if(i %2 != 0)
                       answer += code[i]; 
                }
            }
        }
        if(answer.Length ==0)
            answer = "EMPTY";
        return answer;
    }
}
728x90
반응형
728x90
반응형
배열 조각하기 문제

 

내 코드
using System;
using System.Collections.Generic;
public class Solution {
    public int[] solution(int[] arr, int[] query) {
        List<int> answer = new List<int>(arr);
        for (int i = 0; i < query.Length; i++)
        {
            //012345 //412 >> 4 //01234 // >>1 //1234 // >>2 //123
            if (i % 2 == 0)
            {
                for (int j = answer.Count-1; j > query[i]; j--)
                {
                    answer.RemoveAt(j);
                }
            }
            else
            {
                for (int j = 0; j < query[i]; j++)
                {
                    answer.RemoveAt(0);
                }
            }
            arr = answer.ToArray();
        }
        return answer.ToArray();
    }
}

 

728x90
반응형

+ Recent posts