Skip to content

Commit

Permalink
Improve README.md and 217 in O(n^2)
Browse files Browse the repository at this point in the history
  • Loading branch information
donjuardo committed Jul 10, 2024
1 parent a086b9d commit 29b60e7
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@
<br>
</h1>

<h4 align="center">Solutions to LeetCode problems written in Python 3.</h4>
<h4 align="center">Solutions to LeetCode problems written in Python 3</h4>

The algorithm or technique used, time and space complexities, and optimality are given as comments at the top of each file. Optimality always favors time.
The algorithm or technique used, time complexity, auxiliary space, and
optimality are given as comments at the top of each file. Optimality always
favors time.

> [!NOTE]
> [Binary logarithms](https://en.wikipedia.org/wiki/Binary_logarithm) are notated $\mathop{{}^{}\mathrm{lb}} x$ (e.g., `n lb n`) in compliance with [ISO 80000-2:2019](https://www.iso.org/standard/64973.html).
> [Binary logarithms](https://en.wikipedia.org/wiki/Binary_logarithm), as in
> [logarithmic time](https://en.wikipedia.org/wiki/Time_complexity#Logarithmic_time),
> are notated $\mathop{{}^{}\mathrm{lb}} x$ (e.g., `lb n`) in compliance with
> [ISO 80000-2:2019](https://www.iso.org/standard/64973.html).
## 🧩 Solved

Expand Down
12 changes: 8 additions & 4 deletions python3/217/217-contains-duplicate-a.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
# Programming language: Python 3
# Algorithm/technique: nested iteration
# Time complexity: O(n^2)
# Space complexity: O(1)
# Auxiliary space: O(1)
# Optimal: no
# Notes:

class Solution:
def containsDuplicate(self, nums: list[int]) -> bool:
for i, num in enumerate(nums):
for j in range(i + 1, len(nums)):
if num == nums[j]:
n = len(nums)

# enumerate does not allow the last item to be skipped without slicing,
# which would require O(n) auxiliary space.
for i in range(n - 1):
for j in range(i + 1, n):
if nums[i] == nums[j]:
return True

return False
2 changes: 1 addition & 1 deletion python3/217/217-contains-duplicate-b.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Programming language: Python 3
# Algorithm/technique: sorting
# Time complexity: O(n lb n)
# Space complexity: O(1)
# Auxiliary space: O(1)
# Optimal: no
# Notes:

Expand Down
2 changes: 1 addition & 1 deletion python3/217/217-contains-duplicate-c.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Programming language: Python 3
# Algorithm/technique: set
# Time complexity: O(n)
# Space complexity: O(n)
# Auxiliary space: O(n)
# Optimal: yes
# Notes:

Expand Down
2 changes: 1 addition & 1 deletion python3/217/217-contains-duplicate-d.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Programming language: Python 3
# Algorithm/technique: set
# Time complexity: O(n)
# Space complexity: O(n)
# Auxiliary space: O(n)
# Optimal: yes
# Notes:

Expand Down

0 comments on commit 29b60e7

Please sign in to comment.