프로그래머스 29

[프로그래머스] 3진법 뒤집기 파이썬

https://school.programmers.co.kr/learn/courses/30/lessons/68935 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 내 코드 def solution(n): answer = '' result = 0 while n > 0: answer = str(n % 3) + answer n //= 3 for i in range(len(answer)): result += (int(answer[i]) * 3**i) return result Review 문제를 다 풀고 나서 남들이 푼 코드를 보다가 저번에 n 진법 관련 문제를 풀던..

프로그래머스 2023.06.24

[프로그래머스] 더 맵게 파이썬 heapq

https://school.programmers.co.kr/learn/courses/30/lessons/42626 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 내 코드 import heapq def solution(scoville, K): heapq.heapify(scoville) cnt = 0 while scoville[0] = 2: min_1 = heapq.heappop(scoville) min_2 = heapq.heappop(scoville) heapq.heappush(scoville, min_1 + (mi..

프로그래머스 2023.06.23

[프로그래머스] 정수 제곱근 판별 파이썬

https://school.programmers.co.kr/learn/courses/30/lessons/12934 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 내 코드 def solution(n): a = n ** 0.5 if a == int(a): return (a+1) ** 2 else: return -1 Review n ** 0.5 을 하면 float 타입이 반환이 된다. 루트 씌운 n 값을 정수형(n) 값과 비교해서 같으면 정수 제곱근이다. ex ) n = 121 일때 √n = 11.0 11.0 == int(11.0) True -> 정수 제곱근 ..

프로그래머스 2023.06.20

[프로그래머스] [1차] 캐시

https://school.programmers.co.kr/learn/courses/30/lessons/17680 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 내 코드 # 1차 캐시 from collections import deque def solution(cacheSize, cities): cache = deque([]) cities = map(lambda x: x.lower(), cities) # 모두 소문자로 구분 hit = 1 miss = 5 result = 0 for i in cities: if not i in cache and len(cac..

프로그래머스 2023.06.02

[프로그래머스] 주차 요금 계산 파이썬

https://school.programmers.co.kr/learn/courses/30/lessons/92341 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 내 코드 import math def solution(fees, records): default = 1439 # 23:59 result = {} answer = [] # 차 번호순으로 정렬후 뒤집어 정렬 lst = reversed(sorted(records, key=lambda x: int(x.split()[1]))) for l in lst: i, j, k = l.split() m = int(i[..

프로그래머스 2023.06.01

[프로그래머스] 괄호 변환 파이썬

https://school.programmers.co.kr/learn/courses/30/lessons/60058 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 내 코드 def isComplete(s): result = 0 for j in s: if j == '(': result += 1 else: result -= 1 if result < 0: break if result == 0: return True else: return False def solution(p): global answer # 1. 입력이 빈 문자열인 경우, 빈 문자열을 반환합니다. ..

프로그래머스 2023.05.30

[프로그래머스] 비밀지도 파이썬

https://school.programmers.co.kr/learn/courses/30/lessons/17681 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 내 코드 def solution(n, arr1, arr2): answers = [bin(arr1[i] | arr2[i])[2:] for i in range(n)] for i, answer in enumerate(answers): if len(answer) < n: answers[i] = '0'*(n - len(answer)) + answer result = [] for i in answers: i..

프로그래머스 2023.04.05

[프로그래머스] 개인정보 수집 유효기간 파이썬

https://school.programmers.co.kr/learn/courses/30/lessons/150370 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 내 코드 def todict(a): dictionary = {} for i in a: x, y = i.split() dictionary[x] = int(y)*28 return dictionary def solution(today, terms, privacies): cnt = 1 answer = [] type_dict = todict(terms) today_to_day = (int(today[:4..

프로그래머스 2023.02.05

[프로그래머스] 평행 파이썬

https://school.programmers.co.kr/learn/courses/30/lessons/120875 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 내 코드 def gradient(a, b): # 기울기 계산 return (a[1] - b[1]) / (a[0] - b[0]) def solution(dots): p1, p2, p3, p4 = dots[:4] if gradient(p3, p1) == gradient(p4, p2) or gradient(p4, p3) == gradient(p2, p1): return 1 else: return 0 ..

프로그래머스 2023.02.01

[프로그래머스] 옹알이 (1) 파이썬

https://school.programmers.co.kr/learn/courses/30/lessons/120956 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 내 코드 def solution(babbling): result = 0 for i in babbling: cnt = 0 word = '' for j in i: word += j if word in ['aya', 'ye', 'woo', 'ma']: word = '' cnt += 1 if len(word) == 0 and cnt > 0: result += 1 return result Review 문..

프로그래머스 2023.02.01
반응형
목차(index)