forked from sherigar/HacktoberFest-2023
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a python file with three various approaches
- Loading branch information
1 parent
1867788
commit 96606fb
Showing
1 changed file
with
23 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,23 @@ | ||
#APPROACH -1 | ||
#SORTING THE INITIAL LIST AND RETURNING THE LAST ELEMENT OF LIST | ||
def max(arr): | ||
|
||
arr.sort() | ||
return arr[-1] | ||
#APPROACH -2 | ||
#ITERATING THROUGH ALL THE ELEMENTS IN LIST AND COMPARING EACH ELEMENT | ||
|
||
def max(arr): | ||
|
||
max_element = arr[0] | ||
|
||
for i in range(len(arr)): | ||
if arr[i] > max_element: | ||
max_element = arr[i] | ||
|
||
return (max_element) | ||
|
||
#APPROACH-3 | ||
#USING INBUILT FUNCTION | ||
def max(arr): | ||
return (max(arr)) |