2265. Partition Array According to Given Pivot
My accepted Python solution to LeetCode problem 2265, Partition Array According to Given Pivot, running in 24ms.
- Difficulty: Medium
- Python
- Runtime 24ms
- Memory 31.5MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 24ms, memory 31.5MB, accepted 2025-12-31.
class Solution:
def pivotArray(self, nums: List[int], pivot: int) -> List[int]:
less = []
equal = []
greater = []
for num in nums:
if num < pivot:
less.append(num)
elif num == pivot:
equal.append(num)
else:
greater.append(num)
return less + equal + greater