In my approach, I iterate through the list and count the number of positive and negative numbers separately. If a number is greater than zero, I increase the positive count. If a number is less than zero, I increase the negative count. Finally, I return the maximum count between positive and negative numbers.
class Solution:
def maximumCount(self, nums: List[int]) -> int:
p = 0
n = 0
for i in nums:
if i > 0:
p += 1
elif i < 0:
n += 1
return max(p,n)
- Time: O(n)
- Space: O(1)
