Coding Test/Python(20)
-
[Python] 프로그래머스 / 스택/큐 / 주식가격 / 리스트 숫자 비교
문제 이해 : https://school.programmers.co.kr/questions/20326?question=20326 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr def solution(prices): answer = [] for i in range(len(prices)): time = 0 for j in range(i+1, len(prices)): time += 1 if prices[j]
2024.03.09 -
[Python] 프로그래머스 / 스택/큐 / 다리를 지나는 트럭
https://school.programmers.co.kr/learn/courses/30/lessons/42583#qna 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr def solution(bridge_length, weight, truck_weights): time = 0 # 다리를 건너는 트럭 bridge = [0 for _ in range(bridge_length)] while bridge : time += 1 bridge.pop(0) if truck_weights: # bridge와 다음 truck의 무게가 weight를 넘지않으면 추가 if s..
2024.03.09 -
[Python] 프로그래머스 / 스택/큐 / 프로세스 / any()
https://school.programmers.co.kr/learn/courses/30/lessons/42587 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr def solution(priorities, location): answer = 0 queue = [(i, j) for i, j in enumerate(priorities)] while True: cur = queue.pop(0) if any(cur[1]
2024.03.06 -
[Python] 프로그래머스 / 정렬 / 가장 큰 수 / 숫자형 리스트 단일 값으로 병합
https://school.programmers.co.kr/learn/courses/30/lessons/42746 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr def solution(numbers): numbers = list(map(str, numbers)) # numbers의 원소가 1000이하이기에 4자리를 반복해 정렬 numbers.sort(key=lambda x:x*4, reverse=True) answer = str(int(''.join(numbers))) # str(int())을 하지 않으면 0이 '0000'으로 출력됨 return answ..
2024.03.06 -
[Python] 프로그래머스 / 스택/큐 / 올바른 괄호 / pop() / stack
def solution(s): if s[0]==")" or s[-1]=="(": return False while s and s[0]=="(" and s[-1]==")": for i in range(len(s)): if s[i:i+2]=="()": s = s.replace("()", '') return True #)()) 인데 True 발생 return True replace() 함수는 문자열을 전체적으로 탐색하여 해당 부분을 찾아 치환하기 때문에 매우 비효율적. 특히 반복문 안에서 replace() 함수를 사용하는 것은 반복할 때마다 전체 문자열을 다시 탐색하여 교체하기 때문에 성능이 매우 떨어지게 된다. def solution(s): stack = [] # stack에 '('을 넣어 s의 ')'과 짝..
2024.03.05 -
[Python] 프로그래머스 / 스택/큐 / 기능개발 / 리스트 순서대로 비교
https://school.programmers.co.kr/learn/courses/30/lessons/42586 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr def solution(progresses, speeds): answer = [] num = [] # 작업 시간 for i in range(len(progresses)): work = 100 - progresses[i] if 0=2: if answer[0]>=answer[1]: result += 1 answer.pop(0) else: num.append(result) # num에 추가하고 resu..
2024.03.05