[프로그래머스 | C# | Lv.0] 문자 개수 세기

728x90

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

 

📝 나의 풀이

using System;

public class Solution {
    public int[] solution(string my_string) {
        int[] answer = new int[52];

            foreach (var c in my_string)
            {
                if('A'<=c && c<='Z')
                {
                    answer[c - 'A']++;
                }
                else if ('a'<=c && c<='z')
                {
                    answer[c - 'a' + 26]++;
                }
            }
        return answer;
    }
}

 

 

728x90