Skip to content

Commit b45a44f

Browse files
committed
start from beginning
1 parent 27d7872 commit b45a44f

File tree

123 files changed

+165
-66
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

123 files changed

+165
-66
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# See https://pre-commit.com/hooks.html for more hooks
33
repos:
44
- repo: https://github.com/pre-commit/pre-commit-hooks
5-
rev: v2.4.0
5+
rev: v4.3.0
66
hooks:
77
- id: trailing-whitespace
88
- id: end-of-file-fixer
@@ -13,7 +13,7 @@ repos:
1313
rev: stable
1414
hooks:
1515
- id: black
16-
language_version: python3.7
16+
language_version: python3.10
1717

1818
# - repo: https://gitlab.com/pycqa/flake8
1919
# rev: 3.7.9

Makefile

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
help:
2+
@echo "install - install a virtualenv for development and deployment"
3+
@echo "fmt - format source code with black"
4+
@echo "test - run unit tests"
5+
@echo "deploy - deploy all your pipelines"
6+
@echo "clean - remove build, test, and Python artifacts locally"
7+
8+
VENV = venv
9+
PYTHON = $(VENV)/bin/python3
10+
PIP = $(VENV)/bin/pip
11+
12+
.PHONY: venv
13+
venv:
14+
@test -d "venv" || mkdir -p "venv"
15+
@rm -Rf "venv"
16+
@python3 -m venv "venv"
17+
18+
install: upgrade-pip install-tests
19+
20+
upgrade-pip:
21+
$(PIP) install --upgrade pip setuptools
22+
23+
install-tests:
24+
$(PIP) install -r tests/requirements.txt
25+
26+
fmt:
27+
$(PIP) install black
28+
$(PYTHON) -m black .
29+
30+
test:
31+
export PYTHONPATH=".:./src" && \
32+
$(PYTHON) -m pytest tests/
33+
34+
clean:
35+
@rm -fr .tox/
36+
@rm -fr .venv/
37+
@find . -name '*.egg-info' -exec rm -fr {} +
38+
@find . -name "*.py[co]" -o -name .pytest_cache -exec rm -rf {} +
39+
@find . -name '*.egg' -exec rm -f {} +
40+
@find . -name '*.pyc' -exec rm -f {} +
41+
@find . -name '*.pyo' -exec rm -f {} +
42+
@find . -name '*~' -exec rm -f {} +
43+
@find . -name '__pycache__' -exec rm -fr {} +

easy/1.two_sum.py renamed to bak/1.two_sum.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ def twoSum(self, nums: List[int], target: int) -> List[int]:
2929
return [result[res], index]
3030
else:
3131
result[value] = index
32+
33+
3234
#
3335
#
3436
# # two-pass hash table [Accepted]
@@ -41,6 +43,8 @@ def twoSum(self, nums: List[int], target: int) -> List[int]:
4143
res = target - nums[index]
4244
if res in nums_dict and nums_dict[res] != index:
4345
return [index, nums_dict[res]]
46+
47+
4448
#
4549
#
4650
# # Bruce Force [Not Accepted, Time exceeded]
@@ -51,12 +55,13 @@ def twoSum(self, nums: List[int], target: int) -> List[int]:
5155
if nums[idx1] + nums[idx2] == target:
5256
return [idx1, idx2]
5357

58+
5459
# two pointers
5560
class Solution:
5661
def twoSum(self, nums: List[int], target: int) -> List[int]:
5762
sorted_nums = sorted(nums)
5863
lo = 0
59-
hi = len(nums) -1
64+
hi = len(nums) - 1
6065
while lo < hi:
6166
total = sorted_nums[lo] + sorted_nums[hi]
6267
left = sorted_nums[lo]
@@ -74,5 +79,3 @@ def twoSum(self, nums: List[int], target: int) -> List[int]:
7479
res.append(index)
7580
return res
7681
return []
77-
78-

easy/100.same_tree.py renamed to bak/100.same_tree.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,11 @@ def check(p, q):
9090
return False
9191
return True
9292

93-
deq = deque([(p, q),])
93+
deq = deque(
94+
[
95+
(p, q),
96+
]
97+
)
9498
while deq:
9599
p, q = deq.popleft()
96100
if not check(p, q):
File renamed without changes.

easy/110.balanced_binary_tree.py renamed to bak/110.balanced_binary_tree.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,16 @@ def height(self, node: TreeNode) -> int:
6161
# recursive calculate the height
6262
return 1 + max(self.height(node.left), self.height(node.right))
6363

64-
6564
def isBalanced(self, root: TreeNode) -> bool:
6665
if not root:
6766
return True
6867
# every subtree must be balanced
69-
return abs(self.height(root.left) - self.height(root.right)) < 2 \
70-
and self.isBalanced(root.left) and self.isBalanced(root.right)
68+
return (
69+
abs(self.height(root.left) - self.height(root.right)) < 2
70+
and self.isBalanced(root.left)
71+
and self.isBalanced(root.right)
72+
)
73+
7174

7275
# bottom up solution
7376
class Solution:

0 commit comments

Comments
 (0)