Write a function to reverse a string.
def reverse_string(input_str):
return input_str[::-1]
Example:
reverse_string('hello') # Output: 'olleh'
복습용 저장
복습용 저장
이 항목을 북마크하거나, 어렵게 표시하거나, 복습 세트에 넣을 수 있습니다.
WithoutBook은 주제별 면접 질문, 온라인 연습 테스트, 튜토리얼, 비교 가이드를 하나의 반응형 학습 공간으로 제공합니다.
Know the top Python Coding interview questions and answers for freshers and experienced candidates to prepare for job interviews.
Know the top Python Coding interview questions and answers for freshers and experienced candidates to prepare for job interviews.
Search a question to view the answer.
def reverse_string(input_str):
return input_str[::-1]
Example:
reverse_string('hello') # Output: 'olleh'
이 항목을 북마크하거나, 어렵게 표시하거나, 복습 세트에 넣을 수 있습니다.
def is_palindrome(input_str):
return input_str == input_str[::-1]
Example:
is_palindrome('radar') # Output: True
이 항목을 북마크하거나, 어렵게 표시하거나, 복습 세트에 넣을 수 있습니다.
def is_leap_year(year):
return (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0)
Example:
is_leap_year(2024) # Output: True
이 항목을 북마크하거나, 어렵게 표시하거나, 복습 세트에 넣을 수 있습니다.
def find_max_element(lst):
return max(lst)
Example:
find_max_element([3, 7, 2, 8, 5]) # Output: 8
이 항목을 북마크하거나, 어렵게 표시하거나, 복습 세트에 넣을 수 있습니다.
from collections import Counter
def count_occurrences(lst):
return Counter(lst)
Example:
이 항목을 북마크하거나, 어렵게 표시하거나, 복습 세트에 넣을 수 있습니다.
def is_anagram(str1, str2):
return sorted(str1) == sorted(str2)
Example:
이 항목을 북마크하거나, 어렵게 표시하거나, 복습 세트에 넣을 수 있습니다.
def remove_duplicates(lst):
return list(set(lst))
Example:
이 항목을 북마크하거나, 어렵게 표시하거나, 복습 세트에 넣을 수 있습니다.
def factorial(n):
return 1 if n == 0 else n * factorial(n-1)
Example:
이 항목을 북마크하거나, 어렵게 표시하거나, 복습 세트에 넣을 수 있습니다.
def is_prime(num):
if num < 2:
return False
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
return False
return True
Example:
이 항목을 북마크하거나, 어렵게 표시하거나, 복습 세트에 넣을 수 있습니다.
class Stack:
def __init__(self):
self.items = []
def push(self, item):
self.items.append(item)
def pop(self):
return self.items.pop()
def is_empty(self):
return len(self.items) == 0
Example:
이 항목을 북마크하거나, 어렵게 표시하거나, 복습 세트에 넣을 수 있습니다.
def fibonacci(n):
if n <= 1:
return n
else:
return fibonacci(n-1) + fibonacci(n-2)
Example:
이 항목을 북마크하거나, 어렵게 표시하거나, 복습 세트에 넣을 수 있습니다.
def longest_increasing_subsequence(arr):
n = len(arr)\n lis = [1]*n
for i in range(1, n):
for j in range(0, i):
if arr[i] > arr[j] and lis[i] < lis[j] + 1:
lis[i] = lis[j] + 1
return max(lis)
Example:
이 항목을 북마크하거나, 어렵게 표시하거나, 복습 세트에 넣을 수 있습니다.
def power_set(input_set):
n = len(input_set)
for i in range(1 << n):
subset = [input_set[j]
for j in range(n):
if (i & (1 << j)) > 0]
yield subset
Example:
이 항목을 북마크하거나, 어렵게 표시하거나, 복습 세트에 넣을 수 있습니다.
def binary_search(arr, target):
low, high = 0, len(arr) - 1
while low <= high:
mid = (low + high) // 2
if arr[mid] == target:
return mid
elif arr[mid] < target:
low = mid + 1
else:
high = mid - 1
return -1
Example:
이 항목을 북마크하거나, 어렵게 표시하거나, 복습 세트에 넣을 수 있습니다.
def intersection(list1, list2):
return list(set(list1) & set(list2))
Example:
이 항목을 북마크하거나, 어렵게 표시하거나, 복습 세트에 넣을 수 있습니다.
import numpy as np
matrix1 = np.array([[1, 2], [3, 4]])
matrix2 = np.array([[5, 6], [7, 8]])
result = np.dot(matrix1, matrix2)
Example:
이 항목을 북마크하거나, 어렵게 표시하거나, 복습 세트에 넣을 수 있습니다.
def fibonacci_generator():
a, b = 0, 1
while True:
yield a
a, b = b, a + b
Example:
이 항목을 북마크하거나, 어렵게 표시하거나, 복습 세트에 넣을 수 있습니다.
def dfs(graph, node, visited):
if node not in visited:
print(node)
visited.add(node)
for neighbor in graph[node]:
dfs(graph, neighbor, visited)
Example:
이 항목을 북마크하거나, 어렵게 표시하거나, 복습 세트에 넣을 수 있습니다.
class TreeNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def is_balanced(root):
if root is None:
return True
left_height = height(root.left)
right_height = height(root.right)
return abs(left_height - right_height) <= 1 and is_balanced(root.left) and is_balanced(root.right)
def height(node):
if node is None:
return 0
return max(height(node.left), height(node.right)) + 1
Example:
이 항목을 북마크하거나, 어렵게 표시하거나, 복습 세트에 넣을 수 있습니다.
from collections import OrderedDict
class LRUCache:
def __init__(self, capacity):
self.cache = OrderedDict()
self.capacity = capacitydef get(self, key):
if key in self.cache:
self.cache.move_to_end(key)
return self.cache[key]
return -1def put(self, key, value):
if len(self.cache) >= self.capacity:
self.cache.popitem(last=False)
self.cache[key] = value
self.cache.move_to_end(key)
Example:
이 항목을 북마크하거나, 어렵게 표시하거나, 복습 세트에 넣을 수 있습니다.