대충 만든 자판 - Python

2024. 1. 28. 21:14공부/📝 프로그래머스

1. 풀이 코드

def search_char(string, target_char):
    for index, item in enumerate(string):
        if item == target_char:
            return index + 1
        
    return 0

def solution(keymap, targets):
    answer = []
    
    for item in targets:
        add_index = 0
        
        for target_char in item:
            index = 101
            
            for check_list in keymap:
                temp_index = search_char(check_list, target_char)
                if temp_index != 0:
                    index = min(index, temp_index)

            add_index += index
            if index == 101:
                add_index = -1
                break
                
        answer.append(add_index)
    return answer

  차근차근 문제에서 말하는대로 풀었습니다.


 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

'공부 > 📝 프로그래머스' 카테고리의 다른 글

둘만의 암호 - Python  (0) 2024.01.31
완주하지 못한 선수 - Python  (0) 2024.01.29
문자열 나누기 - Python  (0) 2024.01.27
숫자 짝꿍 - Python  (0) 2024.01.25
로또의 최고 순위와 최저 순위 - Python  (0) 2024.01.24