All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : March 03, 2025
Last updated : March 03, 2025
Related Topics : Array, Two Pointers, Simulation
Acceptance Rate : 89.97 %
class Solution:
def pivotArray(self, nums: List[int], pivot: int) -> List[int]:
output = []
pivot_occ_cnt = 0
for num in nums :
if num < pivot :
output.append(num)
elif num == pivot :
pivot_occ_cnt += 1
output.extend([pivot] * pivot_occ_cnt)
for num in nums :
if num > pivot :
output.append(num)
return output
class Solution:
def pivotArray(self, nums: List[int], pivot: int) -> List[int]:
return sorted(nums, key=lambda x: (x < pivot, x == pivot), reverse=True)