[Coding Test]/[프로그래머스]
[프로그래머스] 단어 변환
https://school.programmers.co.kr/learn/courses/30/lessons/43163 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 이 문제가 BFS를 이용하는 이유: "최소 단계 변환을 찾는 문제 -> 최단 경로 문제 -> BFS를 이용"from collections import dequedef solution(begin, target, words): if target not in words: return 0 q = deque() q.append([begin, 0]) visited = [0]*len(words) def is_one_l..
[프로그래머스] 게임 맵 최단거리
https://school.programmers.co.kr/learn/courses/30/lessons/1844 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr from collections import dequedef solution(maps): n, m = len(maps), len(maps[0]) visited = [ [0]*m for _ in range(n) ] dx = [ 0, 0, -1, 1 ] dy = [ -1, 1, 0, 0 ] def bfs(x, y): visited[x][y] = 1 q = deque() q.append(..
[프로그래머스] 네트워크
문제프로그래머스: 네트워크 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr DFS 풀이def solution(n, computers): visited = [0] * n network_count = 0 def dfs(node): visited[node] = 1 for next_node in range(n): if computers[node][next_node] == 1 and not visited[next_node]: dfs(next_node) for i in range(n): if not visite..
[프로그래머스] 타겟넘버
문제타켓 넘버 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 방법1. 중복 순열 이용from itertools import productdef solution(numbers, target): # 각 숫자에 대해 + 또는 - 를 선택하는 모든 조합 생성 cases = list(product(*[(x, -x) for x in numbers])) # 합이 target인 경우의 개수 반환 return sum(1 for case in cases if sum(case) == target) 데카르트 곱에 관한 내용은 다음 블로그를 참고하시면 됩니다 :) 참고 블로그 중복순열이 가능한 이..
[카카오] 42888 python : 오픈채팅방
https://programmers.co.kr/learn/courses/30/lessons/42888 코딩테스트 연습 - 오픈채팅방 오픈채팅방 카카오톡 오픈채팅방에서는 친구가 아닌 사람들과 대화를 할 수 있는데, 본래 닉네임이 아닌 가상의 닉네임을 사용하여 채팅방에 들어갈 수 있다. 신입사원인 김크루는 카카오톡 오 programmers.co.kr 문자열 파싱을 요구하는 카카오의 코딩테스트 기출문제입니다. 주어진 테스트 케이스 ["Enter uid1234 Muzi", "Enter uid4567 Prodo","Leave uid1234", "Enter uid1234 Prodo","Change uid4567 Ryan"] 이것을 주고 ["Prodo님이 들어왔습니다.", "Ryan님이 들어왔습니다.", "Prodo..