공부/📝 프로그래머스(126)
-
겹치는 선분의 길이 - Python
def solution(lines): temp = [] temp2 = [] for item in lines: for i in range(item[0], item[1]): if i + 0.5 in temp: if i + 0.5 not in temp2: temp2.append(i + 0.5) else: temp.append(i + 0.5) return len(temp2) # Test Cases print(solution([[0, 1], [2, 5], [3, 9]])) print("=" * 50) print(solution([[-1, 1], [1, 3], [3, 9]])) print("=" * 50) print(solution([[0, 5], [3, 9], [1, 10]])) print("=" * 50) se..
2023.10.01 -
안전지대 - 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