Skip to content

Commit 89f84d3

Browse files
committed
better check_partitioned code
1 parent 901fdf5 commit 89f84d3

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

Python/chapter02/2.4 - Partition/miguel_2.4_soln.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,19 +111,16 @@ def check_partitioned(ll: LinkedList, pivot: int) -> bool:
111111
"""
112112
# counter for keeping track of how many times
113113
# we change from < pivot to >= pivot
114-
pivot_change_count = 0
115114
n = ll.head
116115
while n is not None:
117116
if n.data >= pivot:
118-
pivot_change_count += 1
119117
break
120118
n = n.next
121119
while n is not None:
122120
if n.data < pivot:
123-
pivot_change_count += 1
124-
break
121+
return False
125122
n = n.next
126-
return pivot_change_count <= 1
123+
return True
127124

128125

129126
def partition_ll(ll: LinkedList, pivot: int) -> LinkedList:

0 commit comments

Comments
 (0)