본문 바로가기
반응형

프로그래머스/2단계108

(Python/LV2)파일명 압축 문제 출처:https://school.programmers.co.kr/learn/courses/30/lessons/17684 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 풀이: def solution(msg): res = [] dic = {chr(i): i-64 for i in range(ord('A'),ord('Z')+1)} num = 27 while msg: start = 1 while msg[:start] in dic.keys() and start 2022. 10. 1.
(Python/LV2) 방문길이 문제 출처: https://school.programmers.co.kr/learn/courses/30/lessons/49994 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 풀이: def solution(dirs): count = 0 start =[] start.append([0,0]) for i in dirs: if i == "L": start.append([ start[-1][0] -1, start[-1][1] ]) elif i == "R": start.append([ start[-1][0] +1, start[-1][1] ]) elif i == "U".. 2022. 9. 30.
(Python/LV2) 스킬트리 문제 출처: https://school.programmers.co.kr/learn/courses/30/lessons/49993 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 풀이: def solution(skill, skill_trees): pre_skill = skill[:-1] count = 0 for i in skill_trees: if pre_skill in i : count += 1 return count 너무 쉽게 생각했다 당연히 안된다 정답코드: def solution(skill, skill_trees): answer = 0 for tree .. 2022. 9. 28.
(Python/LV2) 땅따먹기 문제 출처: https://school.programmers.co.kr/learn/courses/30/lessons/12913 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 풀이: def solution(land): res = [] print(land[0][:0]) print(land[0][1:]) for i in range(1,len(land)): for j in range(len(land[0])): land[i][j] += max(land[i-1][:j] + land[i-1][j+1:]) # 그전에 쓴 열 제거 하려고 슬라이씽 사용 return max.. 2022. 9. 28.
(Python/LV2) 주식가격 문제출처: https://school.programmers.co.kr/learn/courses/30/lessons/42584 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 풀이: def solution(prices): res = [] while prices: count = 0 now = prices.pop(0) for i in prices: count +=1 if now > i: break res.append(count) return res # 정확성은 100점이지만 # 효율성면에서 다 틀려버린다 정답 코드: def solution(prices) queu.. 2022. 9. 28.
(Python/LV2) 더 맵게 문제 출처: https://school.programmers.co.kr/learn/courses/30/lessons/42626 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 풀이: import heapq def solution(scoville, K): count = 0 heapq.heapify(scoville) while scoville[0] < K : heapq.heappush(scoville, heapq.heappop(scoville) + (heapq.heappop(scoville)*2)) count += 1 if len(scoville) == 1 a.. 2022. 9. 28.
반응형