mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-03-27 17:06:44 +00:00
Fix psf/black issues than fail the build (#1935)
* Fix psf/black issues than fail the build * fixup! Format Python code with psf/black push Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
parent
9b2d65bac1
commit
d1b25760bc
@ -18,7 +18,7 @@ Read our [Contribution Guidelines](CONTRIBUTING.md) before you contribute.
|
|||||||
|
|
||||||
## Community Channel
|
## Community Channel
|
||||||
|
|
||||||
We're on [Gitter](https://gitter.im/TheAlgorithms)! Please join us.
|
We're on [Gitter](https://gitter.im/TheAlgorithms)! Please join us.
|
||||||
|
|
||||||
## List of Algorithms
|
## List of Algorithms
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ class SegmentTreeNode(object):
|
|||||||
self.right = right
|
self.right = right
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return 'val: %s, start: %s, end: %s' % (self.val, self.start, self.end)
|
return "val: %s, start: %s, end: %s" % (self.val, self.start, self.end)
|
||||||
|
|
||||||
|
|
||||||
class SegmentTree(object):
|
class SegmentTree(object):
|
||||||
@ -131,6 +131,7 @@ class SegmentTree(object):
|
|||||||
>>>
|
>>>
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, collection: Sequence, function):
|
def __init__(self, collection: Sequence, function):
|
||||||
self.collection = collection
|
self.collection = collection
|
||||||
self.fn = function
|
self.fn = function
|
||||||
@ -197,7 +198,10 @@ class SegmentTree(object):
|
|||||||
return self._query_range(node.left, i, j)
|
return self._query_range(node.left, i, j)
|
||||||
else:
|
else:
|
||||||
# range in left child tree and right child tree
|
# range in left child tree and right child tree
|
||||||
return self.fn(self._query_range(node.left, i, node.mid), self._query_range(node.right, node.mid + 1, j))
|
return self.fn(
|
||||||
|
self._query_range(node.left, i, node.mid),
|
||||||
|
self._query_range(node.right, node.mid + 1, j),
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
# range in right child tree
|
# range in right child tree
|
||||||
return self._query_range(node.right, i, j)
|
return self._query_range(node.right, i, j)
|
||||||
@ -217,10 +221,11 @@ class SegmentTree(object):
|
|||||||
queue.put(node.right)
|
queue.put(node.right)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
import operator
|
import operator
|
||||||
|
|
||||||
for fn in [operator.add, max, min]:
|
for fn in [operator.add, max, min]:
|
||||||
print('*' * 50)
|
print("*" * 50)
|
||||||
arr = SegmentTree([2, 1, 5, 3, 4], fn)
|
arr = SegmentTree([2, 1, 5, 3, 4], fn)
|
||||||
for node in arr.traverse():
|
for node in arr.traverse():
|
||||||
print(node)
|
print(node)
|
||||||
|
@ -46,11 +46,11 @@ class Stack:
|
|||||||
def size(self):
|
def size(self):
|
||||||
""" Return the size of the stack."""
|
""" Return the size of the stack."""
|
||||||
return len(self.stack)
|
return len(self.stack)
|
||||||
|
|
||||||
def __contains__(self, item) -> bool:
|
def __contains__(self, item) -> bool:
|
||||||
"""Check if item is in stack"""
|
"""Check if item is in stack"""
|
||||||
return item in self.stack
|
return item in self.stack
|
||||||
|
|
||||||
|
|
||||||
class StackOverflowError(BaseException):
|
class StackOverflowError(BaseException):
|
||||||
pass
|
pass
|
||||||
@ -73,4 +73,3 @@ if __name__ == "__main__":
|
|||||||
num = 5
|
num = 5
|
||||||
if num in stack:
|
if num in stack:
|
||||||
print(f"{num} is in stack")
|
print(f"{num} is in stack")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user