공부/📝 프로그래머스(126)
-
[PCCE 기출문제] 9번 / 이웃한 칸 - Python
1. 풀이 코드def solution(board, h, w): answer = 0 up_cell = board[h - 1][w] if h - 1 >= 0 else 'x' down_cell = board[h + 1][w] if len(board) > h + 1 else 'x' left_cell = board[h][w - 1] if w - 1 >= 0 else 'x' right_cell = board[h][w + 1] if len(board) > w + 1 else 'x' for item in [up_cell, down_cell, left_cell, right_cell]: if item == board[h][w]: answer += 1 r..
2024.11.22 -
체육복 - Python
1. 풀이 코드def solution(n, lost, reserve): answer = 0 student_list = [1 for _ in range(n)] for lost_index in lost: lost_index -= 1 student_list[lost_index] -= 1 for reserve_index in reserve: reserve_index -= 1 student_list[reserve_index] += 1 if student_list[0] == 2 and student_list[1] == 0: student_list[0] = 1 student_list[1] = 1..
2024.11.22 -
옹알이 (2) - Python
1. 풀이 코드def solution(babbling): result = 0 for target in babbling: i = -1 while True: if target.startswith("aya"): if i == 1: break i = 1 if len(target) == 3: result += 1 break else: target = target[3:] elif target.start..
2024.08.04 -
둘만의 암호 - Python
1. 풀이 코드 def solution(s, skip, index): alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"] secret_alphabet = [] skip_alphabet = [] for item in skip: skip_alphabet.append(item) for item in alphabet: if item not in skip_alphabet: secret_alphabet.append(item) answer = '' for item in s: answer += secret_alphabe..
2024.01.31 -
완주하지 못한 선수 - Python
1. 풀이 코드 def solution(participant, completion): list1 = sorted(participant) list2 = sorted(completion) for i, item in enumerate(list1): if i < len(list2) and list1[i] != list2[i]: return item elif i == len(list2): return item return -1 위와 같이 풀었습니다. 2. 다른 사람 풀이 코드 def solution(participant, completion): participant.sort() completion.sort() for i in range(len(completion)): if participant[i] != comp..
2024.01.29 -
대충 만든 자판 - Python
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..
2024.01.28 -
문자열 나누기 - Python
1. 풀이 코드 def solution(s): answer = 0 count1 = 0 count2 = 0 char1 = '' for item in s: if char1 == '': char1 = item count1 = 1 else: if char1 == item: count1 += 1 else: count2 += 1 if count1 == count2: answer += 1 count1 = 0 count2 = 0 char1 = '' if char1 != '': answer += 1 return answer 직관적으로 짰습니다. 2. 다른 사람 풀이 코드 def solution(s): answer = 0 sav1=0 sav2=0 for i in s: if sav1==sav2: answer+=1 a=i i..
2024.01.27