분류 전체보기161 *lv2-타겟 넘버 (python, 파이썬) - 1번: 내가 작성한 풀이 from collections import deque def solution(numbers, target): total = sum(numbers) n = len(numbers) operators_list = deque() answer = 0 get_operators([], operators_list, n) for operators in operators_list: res = total for i in range(n): if operators[i] == '-': res -= 2 * numbers[i] if res == target: answer += 1 return answer def get_operators(ops, operators_list, n): if len(ops) =.. 2020. 10. 20. lv2-전화번호 목록 (python, 파이썬) - 1번: 내가 작성한 풀이 def solution(phone_book): lengths = set() pb_dict = dict() for p in phone_book: lengths.add(len(p)) phone_book.sort() for l in lengths: for p in phone_book: if l > len(p): continue if p[:l] in pb_dict.keys() and p[:l] in pb_dict.values(): return False pb_dict[p[:l]] = p return True - 2번: 1번 성공 후 참고한 풀이 def solution2(phone_book): phone_book.sort(key=lambda i: len(i)) for i in rang.. 2020. 10. 20. lv1-문자열 내 마음대로 정렬하기 (python, 파이썬) - 1번: 내가 작성한 풀이 def solution(strings, n): answer = sorted(strings, key=lambda x:x[n]) for x in range(len(answer)): for y in range(x+1, len(answer)): if answer[x][n] == answer[y][n]: if answer[x] > answer[y]: answer[x], answer[y] = answer[y], answer[x] return answer - 2번: 1번 성공 후 참고한 풀이 def solution2(strings, n): return sorted([s for s in strings], key=lambda x: [x[n], x]]) - 3번: 1번 성공 후 참고한 풀이 d.. 2020. 10. 19. lv1-체육복 (python, 파이썬) def solution(n, lost, reserve): student = [1] * (n+1) ans = 0 for x in range(1, n+1): if x in reserve: student[x] += 1 if x in lost: student[x] -= 1 for x in range(1, n): if student[x] > 1 and student[x-1] == 0: student[x-1] += 1 student[x] -= 1 if student[x] > 1 and student[x+1] == 0: student[x+1] += 1 student[x] -= 1 if student[-1] == 2 and student[-2] == 0: student[-2] += 1 student[-1] -= 1 f.. 2020. 10. 19. 이전 1 ··· 11 12 13 14 15 16 17 ··· 41 다음