코딩테스트대비/알고리즘과 친해지기 & 시간복잡도

알파벳 빈도수 찾기 (두번째 풀이)

포비용 2024. 11. 24.
def find_max_occurred_alphabet(string):
    alpha_list = [0] * 26
    # 아스키 코드로 풀기
    for each_string in string:
        if each_string.isalpha():
            alpha_idx = ord(each_string)-97
            alpha_list[alpha_idx] += 1
            
    max_count_idx = alpha_list.index(max(alpha_list))
    find_alpha = chr(max_count_idx+97)
    
    return find_alpha
            

        
result = find_max_occurred_alphabet
print("정답 = i 현재 풀이 값 =", result("hello my name is dingcodingco"))
print("정답 = e 현재 풀이 값 =", result("we love algorithm"))
print("정답 = b 현재 풀이 값 =", result("best of best youtube"))

댓글