Skip to main content

Welcome To CodeCatch

Store, compile, and edit code snippets with other developers on CodeCatch

CodeCatch Logo

158

Users

444

Snippets

86

Languages

Unlimited

Uploads

Store

CodeCatch allows you to easily upload and keep track of code snippets that are important to you. Create a post, upload the post, and never waste your time finding code snippets again.

Compile

CodeCatch supports code compiling for 15+ languages such as JavaScript, Python, C, Go, and more. Simply click the "Run" button when viewing a post to see the compiled output.

1
# Python binary search function
2
def binary_search(arr, target):
3
left = 0
4
right = len(arr) - 1
5
while left <= right:
6
mid = (left + right) // 2
7
if arr[mid] == target:
8
return mid
9
elif arr[mid] < target:
10
left = mid + 1
11
else:
12
right = mid - 1
13
return -1
14
15
# Usage
16
arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
17
target = 7
18
result = binary_search(arr, target)
19
if result != -1:
20
print(f"Element is present at index {result}")
21
else:
22
print("Element is not present in array")
12345678910111213141516171819

Edit

Want to extend or simplify a code snippet? Click the Edit option while viewing a post to easily modify a block of code to your liking.