Algorithms

Programers - 3 _ 핸드폰 번호 가리기

Korokke 2022. 4. 26. 09:14

 

내 풀이:

public class Solution {
    public string solution(string phone_number) {
        
        string answer = "";
        string fourDigits = phone_number.Substring(phone_number.Length - 4, 4) ;
        for(int i = 0; i < phone_number.Length - 4; i++)
        {
            answer += "*";
        }
        answer += fourDigits;
        return answer;
    }
}

다른 풀이:

public class Solution {
    public string solution(string phone_number) {
        string answer = phone_number.Substring(phone_number.Length - 4);
        answer = answer.PadLeft(phone_number.Length, '*');
        return answer;
    }
}