Algorithm 8

[프로그래머스] [python] JadenCase 문자열 만들기

처음에 단순히 공백으로 split하였더니 연속공백에서 걸려서 이런식으로 작성하였다. def solution(string): answer = '' start = True # 처음으로 나왔을때 for s in string: if s != ' ' and start: answer += s.upper() start = False elif s != ' ' and not start: # 공백이 아니고 처음 나온 숫자가 아닐때 answer += s.lower() elif s == ' ': answer += ' ' start = True return answer

Algorithm 2023.01.31

[프로그래머스] BFS / 게임 맵 최단거리

queue 를 이용한 BFS 문제이다. 자세한 설명은 주석을 통해.. from collections import deque def solution(maps): row = len(maps) col = len(maps[0]) dx = [-1, 1, 0, 0] # col 증가는 오른쪽으로 증가 dy = [0, 0, -1, 1] # row 증가는 아래쪽으로 증가 graph = [[-1 for _ in range(col)] for _ in range(row)] # 이동 칸 수를 기록하기 위한 그래프 q = deque() q.append([0,0]) # 시작위치 graph[0][0] = 1 # 시작점은 그자체로 1칸 이동한 것으로 침. while q: y, x = q.popleft() # 행, 열로 탐색할 것이기 ..

Algorithm 2023.01.21

[프로그래머스] 개인정보 수집 유효기간 : 2023 KAKAO BLIND RECRUITMENT

개인정보 파기 기간이 지난 개인정보 고유번호를 출력하는 문제이다. 다음 코드와 같이 현재 날짜, 개인정보 유효기간 날짜등을 모두 일수로 변환하여 비교 후 출력해주므로써 해결. def solution(today, terms, privacies): answer = [] today = list(map(int, today.split('.'))) today_year = int(today[0]) today_month = int(today[1]) today_day = int(today[2]) today_sum = 0 today_sum += today_year * 28 * 12 today_sum += today_month * 28 today_sum += today_day terms_dic = {} for term in..

Algorithm 2023.01.20