Skip to content

Commit

Permalink
feature(C01_P01): add a more optimized sorting solution
Browse files Browse the repository at this point in the history
  • Loading branch information
AshwinRS07 authored and brycedrennan committed Sep 12, 2023
1 parent 86e7826 commit 653e50c
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions chapter_01/p01_is_unique.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ def is_unique_chars_sorting(string: str) -> bool:
return True


# Sorting without extra variable. TC: O(NlogN) SC: O(1) Con: Modifies input string
def is_unique_chars_sort(string: str) -> bool:
string = sorted(string)
for i in range(len(string) - 1):
if string[i] == string[i + 1]:
return False
return True


class Test(unittest.TestCase):
test_cases = [
("abcd", True),
Expand All @@ -86,6 +95,7 @@ class Test(unittest.TestCase):
is_unique_chars_using_dictionary,
is_unique_chars_using_set,
is_unique_chars_sorting,
is_unique_chars_sort,
]

def test_is_unique_chars(self):
Expand Down

0 comments on commit 653e50c

Please sign in to comment.