본문 바로가기

프로그래머스8

[문제 풀이 16] 프로그래머스 - 카드 뭉치 카드 뭉치 문제 유형 : 큐 사용언어 : Python 난이도 : LV. 1 출처 : 프로그래머스 https://school.programmers.co.kr/learn/courses/30/lessons/159994 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr def solution(cards1, cards2, goal): for g in goal: if len(cards1) > 0 and g == cards1[0]: cards1.pop(0) elif len(cards2) > 0 and g == cards2[0]: cards2.pop(0) else: ret.. 2024. 4. 17.
[문제 풀이 14] 프로그래머스 - 기능 개발 기능 개발 문제 유형 :큐 사용언어 : Python 난이도 : LV. 2 출처 : 프로그래머스 https://school.programmers.co.kr/learn/courses/30/lessons/42586 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr import math def solution(progresses, speeds): answer = [] n = len(progresses) days_left = [math.ceil((100-progresses[i])/ speeds[i]) for i in range(n)] count = 0 max_day .. 2024. 4. 16.
[문제 풀이 11] 프로그래머스 - 표 편집 표 편집 문제 유형 : Linked List, Stack 사용언어 : Python 난이도 : LV. 3 출처 : 프로그래머스 https://school.programmers.co.kr/learn/courses/30/lessons/81303 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr def solution(n, k, cmd): state = ["O"] * n # 링크드 리스트 구성 요소 nodes = {i: {'prev': i-1, 'next': i+1} for i in range(n)} nodes[0]['prev'] = None nodes[n-1]['.. 2024. 4. 13.
[문제 풀이 10] 프로그래머스 - 가장 큰 수 가장 큰 수 문제 유형 : Stack 사용언어 : Python 난이도 : LV. 2 출처 : 프로그래머스 https://school.programmers.co.kr/learn/courses/30/lessons/42746 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr def solution(numbers): str_numbers = list(map(str, numbers)) str_numbers.sort(key=lambda x:x*3, reverse=True) answer = ''.join(str_numbers) return answer if answer[.. 2024. 4. 13.
[문제 풀이 8] 프로그래머스 - 크레인 인형 뽑기 게임 크레인 인형 뽑기 게임 문제 유형 : Stack 사용언어 : Python 난이도 : LV. 1 출처 : 프로그래머스 https://school.programmers.co.kr/learn/courses/30/lessons/64061 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr def solution(board, moves): answer = 0 r=len(board) c=len(board[0]) basket = [] for m in moves: for i in range(len(board)): if board[i][m-1] !=0: basket.appen.. 2024. 4. 12.
[문제 풀이 6] 프로그래머스 - 주식 가격 주식 가격 문제 유형 : Stack 사용언어 : Python 난이도 : LV. 2 출처 : 프로그래머스 https://school.programmers.co.kr/learn/courses/30/lessons/42584 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr def solution(prices): n = len(prices) answer = [0]*n stack = [0] for i in range(1, n): while stack and prices[i] < prices[stack[-1]]: j = stack.pop() answer[j] = i-j.. 2024. 4. 11.
[문제 풀이 3] 프로그래머스 - 짝지어 제거하기 짝지어 제거하기 문제 유형 : Stack 사용언어 : Python 난이도 : LV. 2 출처 : 프로그래머스 https://school.programmers.co.kr/learn/courses/30/lessons/12973 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr def solution(s): stack = [] for c in s: if stack and stack[-1]==c: stack.pop() else: stack.append(c) return int(not stack) 2024. 4. 10.
[문제 풀이 2] 프로그래머스 - 괄호 회전하기 괄호 회전하기 문제 유형 : Stack 사용언어 : Python 난이도 : LV. 2 출처 : 프로그래머스 https://school.programmers.co.kr/learn/courses/30/lessons/76502 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr def is_valid(s): stack = [] pair = {')': '(', ']': '[', '}': '{'} for char in s: if char in pair.values(): stack.append(char) elif char in pair: if not stack or pa.. 2024. 4. 10.