Algorithm(116)
-
[프로그래머스 LEVEL2 : 튜플][python]
https://school.programmers.co.kr/learn/courses/30/lessons/64065 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr def solution(s): answer = [] s_list = [] s = s[2:-2].split("},{") for i in s: tmp = list(map(int, i.split(","))) s_list.append(tmp) s_list = sorted(s_list,key=lambda x:len(x)) s_list = sum(s_list, []) for s in s_list: if s ..
2023.03.29 -
[프로그래머스 LEVEL2 : 귤 고르기][python]
https://school.programmers.co.kr/learn/courses/30/lessons/138476# 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr from collections import Counter def solution(k, tangerine): answer = 0 C_tangerine = sorted(dict(Counter(tangerine)).items(), key= lambda x:-x[1]) for _, val in C_tangerine: if k > 0: k -= val answer += 1 else: break retu..
2023.03.22 -
[프로그래머스 LEVEL2 : H-Index][python]
https://school.programmers.co.kr/learn/courses/30/lessons/42747 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr def solution(citations): answer = 0 citations = sorted(citations) for h in range(0,len(citations)+1): for idx, citation in enumerate(citations): r = len(citations) - idx if (h
2023.03.21 -
[프로그래머스 LEVEL1 : 푸드 파이트 대회][python]
https://school.programmers.co.kr/learn/courses/30/lessons/134240# 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr def solution(food): answer = '' result = [] for idx, food in enumerate(food[1:]): if food > 1: result.append(str(idx+1) * (food//2)) result.append('0') result.append("".join(result[-2::-1])) answer = "".join(result) retur..
2023.03.20 -
[프로그래머스 LEVEL2 : 예상 대진표][python]
https://school.programmers.co.kr/learn/courses/30/lessons/12985# 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr import math def solution(n,a,b): answer = 0 while (n >= 2): if (a n //2) or (a > n//2 and b n//2 and b > n//2: a -= n//2 b -= n//2 n = n //2 return answer - 아이디어 1. 예를 들어, n이 8인 경우, a와 b가 각각 1, 5와 같이 n/2를 기준으로 양쪽으로 나뉜 경우, ..
2023.03.18 -
[프로그래머스 LEVEL1 : 가장 가까운 같은 글자][python]
https://school.programmers.co.kr/learn/courses/30/lessons/142086 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr from collections import deque def solution(s): answer = [] d = deque() for si in s: if si not in d: answer.append(-1) else: answer.append(d.index(si)+1) d.appendleft(si) return answer - 아이디어 1. 자신보다 앞에 나왔으면서 동시에 가장 가까운 문자열..
2023.03.15