[프로그래머스] [Python] Level1_K번째 수
https://programmers.co.kr/learn/courses/30/lessons/42748 코딩테스트 연습 - K번째수 [1, 5, 2, 6, 3, 7, 4] [[2, 5, 3], [4, 4, 1], [1, 7, 3]] [5, 6, 3] programmers.co.kr def solution(array, commands): answer = [] #command[0]-1 : slice start #command[1] : slice end #command[2]-1 : index for command in commands: answer.append(sorted(array[command[0]-1:command[1]])[command[2]-1]) return answer 2021.09.29 def so..
2021. 9. 30.
[프로그래머스] [Python] Level2_타겟 넘버
https://programmers.co.kr/learn/courses/30/lessons/43165 코딩테스트 연습 - 타겟 넘버 n개의 음이 아닌 정수가 있습니다. 이 수를 적절히 더하거나 빼서 타겟 넘버를 만들려고 합니다. 예를 들어 [1, 1, 1, 1, 1]로 숫자 3을 만들려면 다음 다섯 방법을 쓸 수 있습니다. -1+1+1+1+1 = 3 +1-1+1+1+ programmers.co.kr 1차 시도 - Stack def solution(numbers, target): answer = 0 stack = [[numbers[0],0], [-1*numbers[0],0]] #[value, idx] n = len(numbers) while stack: temp, idx = stack.pop() #targ..
2021. 8. 5.