목록Language (23)
짧은하루
def solution(k, score): award = [] answer = [] for i, j in enumerate(score): if i k: award.remo..
def solution(n, m, section): answer = 1 tmp = section[0] + m - 1 for i in section[1:]: if i > tmp: answer += 1 tmp = i + m - 1 return answer if __name__ == '__main__': print(solution(8, 4, [2, 3, 6])) # good test case print(solution(10, 3, [1, 5, 10])) 다른 문제 정답 보기 https://github.com/develly/CodingTest/tree/main/programmers
def solution(number, limit, power): answer = 0 for i in range(1, number + 1): cnt = 0 for j in range(1, int(i ** 0.5) + 1): if i % j == 0 and j ** 2 != i: cnt += 2 elif i % j == 0: cnt += 1 if cnt
def solution(k, m, score): answer = 0 score.sort(reverse=True) for i in range(len(score) // m): answer += min(score[i * m: i * m + m]) * m return answer def shorten(k, m, score): """Summarize the code in one line.""" return sum(sorted(score)[len(score) % m::m]) * m if __name__ == '__main__': print(solution(3, 4, [1, 2, 3, 1, 2, 3, 1])) print(shorten(3, 4, [1, 2, 3, 1, 2, 3, 1])) print(shorten(4,..
def solution(s): answer = [] past = [] for i, j in enumerate(s): if j not in past: answer.append(-1) past.append(j) else: answer.append(s[:i][::-1].find(j) + 1) return answer if __name__ == '__main__': print(solution("banana")) 다른 문제 정답 보기 https://github.com/develly/CodingTest/tree/main/programmers
def solution(n, arr1, arr2): answers = [] for i, j in zip(arr1, arr2): i_bin = format(i, 'b').zfill(n) j_bin = format(j, 'b').zfill(n) answer = "" for k in range(n): if any([int(i_bin[k]), int(j_bin[k])]): answer += '#' else: answer += ' ' answers.append(answer) return answers def another_solution(n, arr1, arr2): """Another solution to the same problem.""" answer = [] for i, j in zip(arr1, arr2)..
import re def solution(dartResult): dartResult = dartResult.replace('10', 'A') result = [] for i in dartResult: if i == 'A': result.append(10) elif i.isdigit(): result.append(int(i)) elif i == 'S': pass elif i == 'D': result[-1] = result[-1] ** 2 elif i == 'T': result[-1] = result[-1] ** 3 elif i == '*' and len(result) >= 2: result[-1] = result[-1] * 2 result[-2] = result[-2] * 2 elif i == '*': ..
import datetime def solution(a, b): ans = ['FRI', "SAT", 'SUN', 'MON', "TUE", 'WED', 'THU'] days = b if a != 1: for i in range(a - 1, 0, -1): if i in [1, 3, 5, 7, 8, 11]: days += 31 elif i in [4, 6, 9, 10, 12]: days += 30 else: days += 29 return ans[days % 7 - 1] def shorten(a, b): """Summarize the code in one line.""" month = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] day = ['FRI', 'SAT',..