-
-
Notifications
You must be signed in to change notification settings - Fork 50.3k
added max and min algo #13345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jenyyy4
wants to merge
14
commits into
TheAlgorithms:master
Choose a base branch
from
jenyyy4:anuska2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
added max and min algo #13345
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
e8a7e4f
added max and min algo
jenyyy4 18392e5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] d111a9d
added return type
jenyyy4 781c9b3
merge
jenyyy4 af0f397
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 2a07a21
Merge branch 'master' into anuska2
jenyyy4 33a2fb0
fixed list
jenyyy4 2818711
Merge branch 'anuska2' of https://github.com/jenyyy4/Python into anuska2
jenyyy4 60942d1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] ea1a96e
changed valueerror to none
jenyyy4 050824a
Merge branch 'anuska2' of https://github.com/jenyyy4/Python into anuska2
jenyyy4 26d0845
fixed long line error
jenyyy4 f9cb7a4
trying to fix
jenyyy4 a685ba5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| """ | ||
| Find the maximum and minimum elements in a list. | ||
| Source: https://en.wikipedia.org/wiki/Maximum_and_minimum | ||
|
|
||
| >>> find_max_min([4, 2, 9, 1, 7]) | ||
| (9, 1) | ||
| >>> find_max_min([-5, -10, 0, 5]) | ||
| (5, -10) | ||
| >>> find_max_min([42]) | ||
| (42, 42) | ||
| >>> find_max_min([]) | ||
| """ | ||
|
|
||
| def find_max_min(arr): | ||
| """ | ||
| Returns the maximum and minimum elements of a list. | ||
|
|
||
| Parameters: | ||
| arr (list): The list of numbers. | ||
|
|
||
| Returns: | ||
| tuple: (maximum, minimum) | ||
|
|
||
| Raises: | ||
| ValueError: If the list is empty. | ||
| """ | ||
|
|
||
| if not arr: | ||
| raise ValueError("find_max_min() arg is an empty list") | ||
|
|
||
| maximum = max(arr) | ||
| minimum = min(arr) | ||
| return maximum, minimum | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| examples = [ | ||
| [4, 2, 9, 1, 7], | ||
| [-5, -10, 0, 5], | ||
| [42], | ||
| ] | ||
|
|
||
| for arr in examples: | ||
| max_val, min_val = find_max_min(arr) | ||
| print(f"For list {arr}, maximum: {max_val}, minimum: {min_val}") | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function:
find_max_min. If the function does not return a value, please provide the type hint as:def function() -> None:Please provide type hint for the parameter:
arr