๐ Python
[์์ ํ์] ๋ชจ์๊ณ ์ฌ
def solution(answers): length = len(answers) unit1 = [1, 2, 3, 4, 5] unit2 = [2, 1, 2, 3, 2, 4, 2, 5] unit3 = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5] arr1 = unit1 * (length // 5) + unit1[:length % 5 + 1] arr2 = unit2 * (length // 8) + unit2[:length % 8 + 1] arr3 = unit3 * (length // 10) + unit3[:length % 10 + 1] count1 = 0 count2 = 0 count3 = 0 for i in range(length): if answers[i] == arr1[i]: count1 += ..
[2231] ๋ถํดํฉ
import sys N = sys.stdin.readline().strip() def solve(N): arr = [] for i in range(int(N)+1): temp = i for j in list(str(temp)): temp += int(j) if temp == int(N): arr.append(i) else: pass if len(arr) == 0: return 0 else: return min(arr) print(solve(N)) 2231 ๋ถํดํฉ
[์ ๋ ฌ]H-index
def solution(citations): h = 0 while len([x for x in citations if x >= h]) >= h: h += 1 answer = h -1 return answer ์ ๋ ฌ H-index ๋ค๋ฅธ ํ์ด def solution(citations): citations.sort(reverse=True) answer = max(map(min, enumerate(citations, start=1))) return answer ์... ๋ค๋ฅธ ํ์ด๋ ์ง์ง ์ด๋ ๊ฒ ์๊ฐํด์ ํผ๋ค๋ ๊ฒ ์ ๊ธฐํ๋ค. ์๊ฐ๋ณต์ก๋์์ ๋ด ํ์ด๋์ ๋น๊ต๋ ์๋๊ฒ ๋น ๋ฅด๋ค. enumerate์์ ์ธ๋ฑ์ค ์์์ 1๋ก ํจ์ผ๋ก์จ ๋ฌธ์ ์กฐ๊ฑด์ ๋ง์ท๋ค๋ ์์ด๋์ด๊ฐ ๋๋จ
[์ ๋ ฌ]๊ฐ์ฅ ํฐ ์
from itertools import permutations def solution(numbers): numbers = list(map(str, numbers)) numbers.sort(key = lambda x : x*3, reverse=True) answer = str(int(''.join(numbers))) return answer ์ ๋ ฌ_๊ฐ์ฅ ํฐ ์ ๋ค๋ฅธํ์ด import functools def comparator(a,b): t1 = a+b t2 = b+a return (int(t1) > int(t2)) - (int(t1) < int(t2)) # t1์ด ํฌ๋ค๋ฉด 1 // t2๊ฐ ํฌ๋ค๋ฉด -1 // ๊ฐ์ผ๋ฉด 0 def solution(numbers): n = [str(x) for x in numbers]..
[์ ๋ ฌ]k๋ฒ์งธ ์
def solution(array, commands): answer = [] for command in commands: i = command[0] j = command[1] k = command[2] if i != j: temp = sorted(array[i-1:j])[k-1] answer.append(temp) else: temp = array[i-1] answer.append(temp) return answer ์ ๋ ฌ k๋ฒ์งธ ์ ๋ค๋ฅธํ์ด def solution(array, commands): return list(map(lambda x:sorted(array[x[0]-1:x[1]])[x[2]-1], commands)) ๋๋ค๋ฅธํ์ด def solution(array, commands): answer = ..