-
-
Notifications
You must be signed in to change notification settings - Fork 46.6k
Patch 5 #9378
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
Closed
Closed
Patch 5 #9378
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
3491a98
feat(cellular_automata): Create wa-tor algorithm
CaedenPH a052365
updating DIRECTORY.md
f79680b
chore(quality): Implement algo-keeper bot changes
CaedenPH 0a192e8
build: Fix broken ci
CaedenPH 2fe6444
git rm cellular_automata/wa_tor.py
cclauss 3f95987
updating DIRECTORY.md
e2a0a4f
Create add_nodes
Diald 1997470
Delete data_structures/linked_list/add_nodes
Diald 4620267
Add files via upload
Diald 4608a23
Merge pull request #2 from Diald/Diald-patch-6
Diald 1e6b33b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 7e934f1
Update kadanes_algorithm.py
Diald 41d6d00
Add files via upload
Diald 8d200dc
Merge pull request #3 from Diald/Diald-patch-7
Diald 39e6fba
Update two_sum_advance.py
Diald bf02546
[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 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,30 @@ | ||
"""Given an integer array nums, find the subarray with the largest sum, and return its sum. | ||
Example 1: | ||
Input: nums = [-2,1,-3,4,-1,2,1,-5,4] | ||
Output: 6 | ||
Explanation: The subarray [4,-1,2,1] has the largest sum 6. | ||
Example 2: | ||
Input: nums = [1] | ||
Output: 1 | ||
Explanation: The subarray [1] has the largest sum 1. | ||
Example 3: | ||
Input: nums = [5,4,-1,7,8] | ||
Output: 23 | ||
Explanation: The subarray [5,4,-1,7,8] has the largest sum 23. | ||
""" | ||
|
||
|
||
def max_subArray(self, nums: List[int]) -> int: | ||
# kadane's algorithm# | ||
curr = 0 | ||
maxtillnow = -inf | ||
for c in nums: | ||
curr = max(c, curr + c) | ||
maxtillnow = max(curr, maxtillnow) | ||
return maxtillnow | ||
|
||
|
||
if __name__ == "__main__": | ||
import doctest | ||
|
||
doctest.testmod() |
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,47 @@ | ||
"""<----------------------------------------2 POINTER SOLUTION ---------------------------------------> | ||
|
||
Given a 1-indexed array of integers numbers that is already sorted in non-decreasing order, find two numbers such that they add up to a specific target number. Let these two numbers be numbers[index1] and numbers[index2] where 1 <= index1 < index2 < numbers.length. | ||
Return the indices of the two numbers, index1 and index2, added by one as an integer array [index1, index2] of length 2. | ||
The tests are generated such that there is exactly one solution. You may not use the same element twice. | ||
Your solution must use only constant extra space. | ||
Example 1: | ||
|
||
Input: numbers = [2,7,11,15], target = 9 | ||
Output: [1,2] | ||
Explanation: The sum of 2 and 7 is 9. Therefore, index1 = 1, index2 = 2. We return [1, 2]. | ||
Example 2: | ||
|
||
Input: numbers = [2,3,4], target = 6 | ||
Output: [1,3] | ||
Explanation: The sum of 2 and 4 is 6. Therefore index1 = 1, index2 = 3. We return [1, 3]. | ||
Example 3: | ||
|
||
Input: numbers = [-1,0], target = -1 | ||
Output: [1,2] | ||
Explanation: The sum of -1 and 0 is -1. Therefore index1 = 1, index2 = 2. We return [1, 2]. | ||
|
||
|
||
#-------------------------CODE----------------# """ | ||
|
||
|
||
def two_sum(self, numbers: List[int], target: int) -> List[int]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As there is no test file in this pull request nor any test function or class in the file |
||
n = len(numbers) | ||
l = 0 | ||
r = n - 1 | ||
res = [] | ||
while l < r: | ||
if numbers[l] + numbers[r] == target: | ||
res.append(l + 1) | ||
res.append(r + 1) | ||
if numbers[l] + numbers[r] > target: | ||
r -= 1 | ||
else: | ||
l += 1 | ||
res.sort() | ||
return res | ||
|
||
|
||
if __name__ == "__main__": | ||
import doctest | ||
|
||
doctest.testmod() |
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 |
---|---|---|
|
@@ -9,6 +9,7 @@ pandas | |
pillow | ||
projectq | ||
qiskit | ||
qiskit-aer | ||
requests | ||
rich | ||
scikit-fuzzy | ||
|
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.
Variable and function names should follow the
snake_case
naming convention. Please update the following name accordingly:max_subArray
As there is no test file in this pull request nor any test function or class in the file
data_structures/arrays/kadanes_algorithm.py
, please provide doctest for the functionmax_subArray