Skip to content

Leetcode subarray sum equals k#4

Open
Igneaalis wants to merge 8 commits intomasterfrom
LEETCODE-subarray-sum-equals-k
Open

Leetcode subarray sum equals k#4
Igneaalis wants to merge 8 commits intomasterfrom
LEETCODE-subarray-sum-equals-k

Conversation

@Igneaalis
Copy link
Copy Markdown
Owner

No description provided.

@Igneaalis Igneaalis requested a review from Vivelapaix May 13, 2020 15:42
arrays.md Outdated
:rtype: List[int]
"""

out = {}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Надо линейное решение без доп.памяти

arrays.md Outdated
:rtype: List[int]
"""

for i, v in enumerate(nums):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Усложнил, можно проще за линию

@@ -0,0 +1,127 @@
# Arrays

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

На каждую задачу отдельный Pull Request

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

@Vivelapaix разделил на три ветки.

:rtype: int
"""

_list, _dict, sums_count = [0] + [sum(nums[:index + 1]) for index in range(len(nums))], defaultdict(int), 0
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Придется упростить через кумулятивную сумму. Слишком сложно да и еще с подсчетом сумм

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Я хотел добавить импорт, но leetcode как-то не может это сделать, поэтому переписал в виде генератора списка. Можно сделать и через reduce, наверное. С reduce, может, попроще станет, стоит ли?

@Igneaalis Igneaalis changed the title arrays.md solutions Leetcode subarray sum equals k Jun 4, 2020
@Igneaalis Igneaalis added the question Further information is requested label Jun 5, 2020
@Igneaalis Igneaalis requested a review from Vivelapaix June 5, 2020 00:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

question Further information is requested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants