题目:
给你一个按 非递减顺序 排列的数组 nums ,返回正整数数目和负整数数目中的最大值。
- 换句话讲,如果
nums中正整数的数目是pos,而负整数的数目是neg,返回pos和neg二者中的最大值。
注意:0 既不是正整数也不是负整数。
思考:
暴力解法,遍历数组判断正负即可。代码如下:
class Solution(object):
def maximumCount(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
pos = 0
neg = 0
for num in nums:
if num > 0:
pos += 1
elif num < 0:
neg += 1
return max(pos, neg)
提交通过:
1427

被折叠的 条评论
为什么被折叠?



