Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions math/add.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def add(a: int, b: int) -> int:

Check failure on line 1 in math/add.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (INP001)

math/add.py:1:1: INP001 File `math/add.py` is part of an implicit namespace package. Add an `__init__.py`.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide descriptive name for the parameter: a

Please provide descriptive name for the parameter: b

"""
Return sum of two integers

>>> add(2, 3)
5
>>> add(-1, 1)
0
"""
if not isinstance(a, int) or not isinstance(b, int):
raise ValueError("Inputs must be integers")
return a + b
23 changes: 23 additions & 0 deletions searches/boyer_moore_majority_vote.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
def majority_element(nums: list[int]) -> int:
"""
Find majority element using Boyer-Moore Voting Algorithm
https://en.wikipedia.org/wiki/Boyer%E2%80%93Moore_majority_vote_algorithm

>>> majority_element([3, 3, 4])
3
>>> majority_element([2, 2, 1, 1, 2, 2, 2])
2
"""

if not nums:
raise ValueError("List cannot be empty")

candidate = None
count = 0

for num in nums:
if count == 0:
candidate = num
count += 1 if num == candidate else -1

return candidate
Loading