-
-
Notifications
You must be signed in to change notification settings - Fork 46.8k
added sleepsort.py #6959
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
added sleepsort.py #6959
Changes from all commits
b9c7a17
f1cd3ec
8ba36a1
4ef0c9a
38e2790
bc56774
cb0b8c5
5fc6444
d929b71
ec09f3f
b12a42e
3491901
d3abc71
8441f5e
3fd11fe
5d1ee49
7961ea3
5691596
ad94248
1993cb9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from time import sleep | ||
|
||
import thread | ||
|
||
items = [] | ||
n = int(input()) | ||
for i in range(0, n): | ||
a = int(input()) | ||
items.append(a) | ||
|
||
|
||
def sleep_sort(i): | ||
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 Please provide return type hint for the function: Please provide type hint for the parameter: Please provide descriptive name for the parameter: |
||
sleep(i) | ||
print(i) | ||
|
||
|
||
[thread.start_new_thread(sleep_sort, (i,)) for i in items] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
def longest_valid_parenthesis(s: str) -> 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. Please provide descriptive name for the parameter: 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. Please provide descriptive name for the parameter: |
||
""" | ||
Returns the length of the longest valid parenthesis | ||
>>> longest_valid_parenthesis('(()') | ||
2 | ||
>>> longest_valid_parenthesis(')()())') | ||
4 | ||
>>> longest_valid_parenthesis('(()()()()))') | ||
10 | ||
>>> longest_valid_parenthesis(''(())))((()(()()()()) | ||
8 | ||
""" | ||
stack = [] | ||
preceeding_matched = 0 | ||
res = 0 | ||
for char in s: | ||
if char == "(": | ||
stack.append(preceeding_matched) | ||
preceeding_matched = 0 | ||
else: | ||
if stack: | ||
preceeding_matched += 1 + stack.pop() | ||
else: | ||
res = max(res, preceeding_matched) | ||
preceeding_matched = 0 | ||
res = max(res, preceeding_matched) | ||
while stack: | ||
res = max(res, stack.pop()) | ||
return res * 2 | ||
|
||
|
||
if __name__ == "__main__": | ||
s = input() | ||
print(longest_valid_parenthesis(s)) |
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.
As there is no test file in this pull request nor any test function or class in the file
sorts/sleepsort.py
, please provide doctest for the functionsleep_sort
Please provide return type hint for the function:
sleep_sort
. If the function does not return a value, please provide the type hint as:def function() -> None:
Please provide type hint for the parameter:
i
Please provide descriptive name for the parameter:
i