목록Python (42)
눈송이의 개발생활
문제 https://www.acmicpc.net/problem/2467 코드 import sys input = lambda : sys.stdin.readline().strip() n = int(input()) arr = list(map(int, input().split())) min_n = sys.maxsize ans_s, ans_e = 0, len(arr)-1 s, e = 0, len(arr)-1 while s 0: e -= 1 elif summ < 0: s += 1 else: break print(arr[ans_s], arr[a..
문제 https://school.programmers.co.kr/learn/courses/30/lessons/42584 내 코드 - 효율성 테스트 실패 def solution(prices): answer = [] while prices: temp = prices.pop(0) cnt = 0 for i in range(len(prices)): if prices[i] >= temp: cnt += 1 else: cnt += 1 break answer.append(cnt) return answer 다른 사람 풀이 from collections import deque def solution(prices): answer = [] p = deque(prices) while p: temp = p.popleft() cnt..
문제 https://programmers.co.kr/learn/courses/30/lessons/42747 내 코드 def solution(citations): count = 0 citations.sort() for i in range(citations[-1] + 1): new_c = [j for j in range(len(citations)) if citations[j] >= i] if len(new_c) >= i: count = i else: break return count 다른 사람 풀이 def solution(citations): citations = sorted(citations) l = len(citations) for i in range(l): if citations[i] >= l-i: r..
문제 https://programmers.co.kr/learn/courses/30/lessons/42576 내 코드 #1 (실패) def solution(participant, completion): for i in range(len(completion)): if completion[i] in participant: participant.remove(completion[i]) answer = participant[0] if len(participant) != 0 else ' ' return answer 내 코드 #2 (성공) def solution(participant, completion): participant.sort() completion.sort() for p, c in zip(participa..
문제 https://programmers.co.kr/learn/courses/30/lessons/42748 내 코드 def solution(answers): students = [ [1, 2, 3, 4, 5], [2, 1, 2, 3, 2, 4, 2, 5], [3, 3, 1, 1, 2, 2, 4, 4, 5, 5] ] answer = [0, 0, 0] result = [] for i in range(len(answers)): if answers[i] == students[0][i % 5]: answer[0] += 1 if answers[i] == students[1][i % 8]: answer[1] += 1 if answers[i] == students[2][i % 10]: answer[2] += 1 m =..
문제 https://programmers.co.kr/learn/courses/30/lessons/42748 내 코드 def solution(array, commands): answer = [] for index in range(len(commands)): temp = [] i = commands[index][0] - 1 j = commands[index][1] k = commands[index][2] - 1 temp = array[i:j] temp.sort() answer.append(temp[k]) return answer 다른 사람 풀이 def solution(array, commands): answer = [] for command in commands: i,j,k = command answer.a..
문제 https://programmers.co.kr/learn/courses/30/lessons/42862 내 코드 def solution(n, lost, reserve): s_res = set(reserve) - set(lost) s_lost = set(lost) - set(reserve) for i in s_res: if i - 1 in s_lost: s_lost.remove(i - 1) elif i + 1 in s_lost: s_lost.remove(i + 1) return n - len(s_lost) 다른 사람 풀이 def solution(n, lost, reserve): _reserve = [r for r in reserve if r not in lost] _lost = [l for l in l..
문제 https://programmers.co.kr/learn/courses/30/lessons/17682 내 코드 def solution(dartResult): dartResult = dartResult.replace('10', 'k') bonus = {'S': 1, 'D': 2, 'T': 3} temp = [] for i in dartResult: if i.isdigit(): temp.append(int(i)) elif i == 'k': temp.append(10) elif i in bonus: temp[-1] = temp[-1] ** bonus[i] elif i == '#': temp[-1] *= -1 elif i == '*': temp[-1] *= 2 if len(temp) > 1: temp[-2..