C# 모음 제거 - 프로그래머스 [Lv.0] 코딩 테스트 입문

출처: 프로그래머스 코딩 테스트 연습
https://school.programmers.co.kr/learn/courses/30/lessons/120849

 

 

나의 풀이

using System;

public class Solution {
    
    string[] replaceText = new string[5]{ "a", "i", "o", "e", "u" };
    
    public string solution(string my_string) {
        
        string answer = my_string;
        foreach(string text in replaceText)
            answer = answer.Replace(text, "");
        
        return answer;
    }
}

 

 

다른 사람 풀이1

using System;
using System.Text.RegularExpressions;

public class Solution {
    public string solution(string my_string) {
        string answer = Regex.Replace(my_string, @"a|e|i|o|u", "");
        return answer;
    }
}

Regex를 이용한 풀이 1

 

다른 사람 풀이2

using System;
using System.Text.RegularExpressions;

public class Solution {
    public string solution(string my_string) {
        return Regex.Replace(my_string,"[a,e,i,o,u]","");
    }
}

Regex를 이용한 풀이 2

 

댓글

Designed by JB FACTORY