목록Algorithm/프로그래머스 (26)
내 인생은 개발 중

https://school.programmers.co.kr/learn/courses/30/lessons/49994 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.krdef solution(dirs): visited = set() direction = {'U': (1, 0), 'D': (-1, 0), 'R': (0, 1), 'L': (0, -1)} y, x = 0, 0 for d in dirs: dy, dx = direction[d] ny, nx = y + dy, x + dx if -5 처음엔 딕셔너리에..

https://school.programmers.co.kr/learn/courses/30/lessons/152996 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr 풀이from collections import Counterdef solution(weights): answer = 0 counter = Counter(weights) for k, v in counter.items(): if v >= 2: answer += v * (v - 1) // 2 weights = set(weights) for w i..

https://school.programmers.co.kr/learn/courses/30/lessons/42883# 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr def solution(number, k): answer = [] for i in number: if not answer: answer.append(i) continue if k > 0: while answer[-1] 0: answer = answer[:len(answer) - k] ..

https://school.programmers.co.kr/learn/courses/30/lessons/42626 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr import heapqdef solution(scoville, K): answer = 0 heapq.heapify(scoville) while scoville[0] 알게된 점heapify 사용하면 기존의 리스트를 힙 자료형으로 바꿀 수 있다.heappop()은 가장 작은 원소를 제거하는 동시에 그를 결괏값으로 리턴한다.heap에서 가장 작은 원소를 삭제하지 않고 가져오고 싶으면 hea..

https://school.programmers.co.kr/learn/courses/30/lessons/84512 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr from itertools import productdef solution(word): dict = [] vowels = ['A', 'E', 'I', 'O', 'U'] for i in range(1, 6): for v in product(vowels, repeat = i): dict.append(''.join(list(v))) dict.sort(..

https://school.programmers.co.kr/learn/courses/30/lessons/42577 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr def solution(phone_book): answer = True phone_book.sort() for num in range(len(phone_book) - 1): if phone_book[num] in phone_book[num + 1] and phone_book[num + 1].index(phone_book[num]) == 0: answ..
https://school.programmers.co.kr/learn/courses/30/lessons/42860 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr 💻 풀이def solution(name): answer = 0 n = len(name) # 기본 최소 이동거리 min_move = n - 1 # 리스트를 전부 돌면서 최소 이동거리 구해주기 for i, char in enumerate(name): # 알파벳 이동만큼 정답에 더해주기 # Z는 A에서 Z로 이동 한 번 더 해야하니깐 + 1 해주기..

https://school.programmers.co.kr/learn/courses/30/lessons/49191 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr 풀이from collections import Counterdef solution(n, results): answer = 0 board = [[0] * n for _ in range(n)] # 이겼으면 1 졌으면 -1로 표시해주기 for a, b in results: board[a - 1][b - 1] = 1 board[b - 1][a - 1] = -1 ..