๐Ÿ 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 = ..