전체 글(178)
-
안전지대 - Python
def solution(board): answer = 0 n, m = len(board), len(board[0]) check_list = [[0] * (m + 2) for _ in range(n + 2)] for i in range(n): for j in range(m): check_list[i + 1][j + 1] = board[i][j] for i in range(1, n + 1): for j in range(1, m + 1): temp = ( check_list[i][j] + check_list[i - 1][j - 1] + check_list[i][j - 1] + check_list[i + 1][j - 1] + check_list[i - 1][j] + check_list[i + 1][j] + ch..
2023.10.01 -
연속된 수의 합 - Python
def solution(num, total): answer = [] if num % 2: start = total // num - (num - 1) // 2 end = total // num + (num - 1) // 2 for i in range(start, end + 1): answer.append(i) else: start = total // num - num // 2 + 1 end = total // num + num // 2 for i in range(start, end + 1): answer.append(i) return answer # Test Cases print(solution(3, 12)) print("=" * 50) print(solution(5, 15)) print("=" * 50)..
2023.10.01 -
다음에 올 숫자 - Python
def solution(common): if common[1] - common[0] == common[2] - common[1]: return common[-1] + common[1] - common[0] else: return common[-1] * (common[1] / common[0]) # Test Cases print(solution([1, 2, 3, 4])) print("=" * 50) print(solution([2, 4, 8])) print("=" * 50) 위와 같이 풀었습니다. def solution(common): answer = 0 a,b,c = common[:3] if (b-a) == (c-b): return common[-1]+(b-a) else: return common[-1]..
2023.10.01 -
OX퀴즈 - Python
def solution(quiz): answer = [] for item in quiz: a, b = item.split(" = ") if eval(a) == int(b): answer.append("O") else: answer.append("X") return answer # Test Cases print(solution(["3 - 4 = -3", "5 + 6 = 11"])) print("=" * 50) print(solution(["19 - 6 = 13", "5 + 66 = 71", "5 - 15 = 63", "3 - 1 = 2"])) print("=" * 50) 위와 같이 풀었습니다. def valid(equation): equation = equation.replace('=', '==') ret..
2023.10.01 -
특이한 정렬 - Python
def solution(numlist, n): answer = [] temp_list = [] for item in numlist: temp_list.append(abs(item - n)) temp_list.sort() for item in temp_list: if n + item in numlist: answer.append(n + item) del numlist[numlist.index(n + item)] else: answer.append(n - item) del numlist[numlist.index(n - item)] return answer # Test Cases print(solution([1, 2, 3, 4, 5, 6], 4)) print("="*50) print(solution([1000..
2023.10.01 -
문자열 밀기 - Python
def solution(A, B): answer = 0 for i in range(len(A)): if A == B: return answer else: temp = A[-1] + A[:-1] A = temp answer += 1 return -1 # Test Cases print(solution("hello", "ohell")) print("="*50) print(solution("apple", "elppa")) print("="*50) print(solution("atat", "tata")) print("="*50) print(solution("abc", "abc")) print("="*50) 위와 같이 풀었습니다. solution=lambda a,b:(b*2).find(a) 다른 사람의 풀이입니다...
2023.09.30 -
유한소수 판별하기 - Python
def solution(a, b): divisor = 2 while divisor
2023.09.30 -
치킨 쿠폰 - Python
def solution(chicken): answer = chicken // 10 inventory = [chicken % 10, chicken // 10] while sum(inventory) >= 10: if inventory[0] >= 10: inventory[0] -= 10 inventory[1] += 1 answer += 1 elif inventory[1] >= 10: inventory[1] -= 10 inventory[0] += 1 answer += 1 elif sum(inventory) >= 10: inventory = [0, 1] answer += 1 return answer # Test Cases print(solution(100)) print("="*50) print(solution(1..
2023.09.30 -
등수 매기기 - Python
def solution(score): answer = [] avg_score = [] [avg_score.append(sum(item)/2) for item in score] rank = sorted(avg_score, reverse=True) [answer.append(rank.index(item) + 1) for item in avg_score] return answer # Test Cases print(solution([[80, 70], [90, 50], [40, 70], [50, 80]])) print("="*50) print(solution([[80, 70], [70, 80], [30, 50], [ 90, 100], [100, 90], [100, 100], [10, 30]])) print("="..
2023.09.30 -
로그인 성공? - Python
def solution(id_pw, db): for item in db: if item[0] == id_pw[0]: if item[1] == id_pw[1]: return "login" else: return "wrong pw" return "fail" # Test Cases print(solution(["meosseugi", "1234"], [["rardss", "123"], ["yyoom", "1234"], ["meosseugi", "1234"]])) print("="*50) print(solution(["programmer01", "15789"], [["programmer02", "111111"], [ "programmer00", "134"], ["programmer01", "1145"]])) pr..
2023.09.30