aboutsummaryrefslogtreecommitdiff
path: root/max_cnt_pos_neg_int.py
diff options
context:
space:
mode:
authorJack Sangdahl <[email protected]>2025-03-11 21:13:37 -0600
committerJack Sangdahl <[email protected]>2025-03-11 21:13:37 -0600
commitb477c5d538f1fef91dbf906a17411eef32b2ded2 (patch)
tree49244d26df49c557e556fcdc7c0f8ae2a1a1add3 /max_cnt_pos_neg_int.py
parent550458b5ef4a31e8c95e4fcd0f22bc6ca59fd46e (diff)
downloadleetcode-b477c5d538f1fef91dbf906a17411eef32b2ded2.tar.gz
leetcode-b477c5d538f1fef91dbf906a17411eef32b2ded2.zip
2529. maximum count of positive integer and negative integer
Diffstat (limited to 'max_cnt_pos_neg_int.py')
-rw-r--r--max_cnt_pos_neg_int.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/max_cnt_pos_neg_int.py b/max_cnt_pos_neg_int.py
new file mode 100644
index 0000000..068a6e3
--- /dev/null
+++ b/max_cnt_pos_neg_int.py
@@ -0,0 +1,24 @@
+# 2529. Maximum Count of Positive Integer and Negative Integer
+from bisect import bisect_left
+
+"""
+given an array 'nums' sorted in non-decreasing order, return the maximum
+between the number of positive integers and he number of negative integers.
+note that '0' is neither positive nor negative.
+"""
+
+
+class Solution(object):
+ def maximumCount(self, nums):
+ """
+ :type nums: List[int]
+ :rtype: int
+ """
+ return max(bisect_left(nums, 0), len(nums) - bisect_left(nums, 1))
+
+
+if __name__ == "__main__":
+ obj = Solution()
+ print(obj.maximumCount(nums=[-2, -1, -1, 1, 2, 3]))
+ print(obj.maximumCount(nums=[-3, -2, -1, 0, 0, 1, 2]))
+ print(obj.maximumCount(nums=[5, 20, 66, 1314]))