LeetCode solutions

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

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 24ms, memory 31.5MB, accepted 2025-12-31.

python
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

Source