💻 하나씩 차곡차곡/프로그래머스 (Python)
-
[프로그래머스/Lv.1/Python] 모의고사💻 하나씩 차곡차곡/프로그래머스 (Python) 2024. 1. 26. 13:46
def solution(answers): answer = [] supoja1 = [1, 2, 3, 4, 5] supoja2 = [2, 1, 2, 3, 2, 4, 2, 5] supoja3 = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5] score = [0, 0, 0] for idx, value in enumerate(answers) : if value == supoja1[idx % len(supoja1)]: score[0] += 1 if value == supoja2[idx % len(supoja2)]: score[1] += 1 if value == supoja3[idx % len(supoja3)]: score[2] += 1 for idx, s in enumerate(score): if s ==..
-
[프로그래머스/Lv2/Python] 큰 수 만들기💻 하나씩 차곡차곡/프로그래머스 (Python) 2024. 1. 23. 09:52
def solution(number, k): stack = [number[0]] for num in number[1:]: while len(stack) > 0 and stack[-1] 0: k -= 1 stack.pop() stack.append(num) if k != 0: stack = stack[:-k] return ''.join(stack) 문제 이해 자체가 너무 어려웠고 그래서 결국 자꾸 하나가 테스트 안넘어 가서....다른 분 풀이 가지고 옴. stack을 사용했고 마지막에 if k!= 0 부분 까지 처리해주지 않으면 예외처리가 안된다는 것을 명심.
-
[프로그래머스/Lv2/Python] 구명보트💻 하나씩 차곡차곡/프로그래머스 (Python) 2024. 1. 22. 09:32
def solution(people, limit): answer = 1 people.sort() weigth = 0 for i in people: if limit < weigth + i: answer += 1 weigth = i else : weigth += i return answer 일케 짰는데 테스트 통과하고 정확성 22퍼센트대로 ㅋㅋㅋㅋㅋㅋㅋ거의 틀린거나 다름 없이 됨. 다른 분 풀이를 가지고 왔다........ def solution(people, limit): people.sort() start, end = 0, len(people)-1 count = 0 while start
-
[프로그래머스/Python] [PCCP 모의고사 #1] 1번 - 외톨이 알파벳💻 하나씩 차곡차곡/프로그래머스 (Python) 2024. 1. 18. 13:17
def solution(input_string): answer = '' count = {} answer_list = [] # {알파벳 : [알파벳이 있는 인덱스]} for idx, alpha in enumerate(input_string): if alpha not in count: count[alpha] = [idx] else: count[alpha].append(idx) for key, value in count.items(): if len(value) >= 2: for i in range(len(value) - 1): if abs(value[i]-value[i+1]) > 1: answer_list.append(key) break if len(answer_list) == 0: answer = "N" e..
-
[프로그래머스/LV.1/Python] 체육복💻 하나씩 차곡차곡/프로그래머스 (Python) 2024. 1. 17. 14:08
첫 도전 ... def solution(n, lost, reserve): answer = n - len(lost) for i in range(len(lost)): if n == lost[i]: # 마지막 번호일경우 if lost[i-1] in reserve : answer += 1 reserve.remove(lost[i]-1) elif lost[i] == 1 : # 첫번째 번호일경우 if lost[i+1] in reserve : answer += 1 reserve.remove(lost[i]+1) else : if lost[i]-1 in reserve: answer += 1 reserve.remove(lost[i]-1) elif lost[i]+1 in reserve: answer += 1 reserve.r..