본문 바로가기
python-algorithm

leetcode 2529. Maximum Count of Positive Integer and Negative Integer

by 무적김두칠 2023. 1. 10.

https://leetcode.com/problems/maximum-count-of-positive-integer-and-negative-integer/description/

 

Maximum Count of Positive Integer and Negative Integer - LeetCode

Maximum Count of Positive Integer and Negative Integer - Given an array nums sorted in non-decreasing order, return the maximum between the number of positive integers and the number of negative integers. * In other words, if the number of positive integer

leetcode.com

 

1
2
3
4
5
6
7
from bisect import bisect_left
class Solution:
    def maximumCount(self, nums: List[int]) -> int:
        answer = max(bisect_left(nums,0),len(nums)-bisect_left(nums,0)-nums.count(0))
 
        return answer
 
cs

bisect이용해서 0이 들어갈 위치 찾으셔서 해결하시면 됩니더

You can use bisect to find the location where the 0 will go and solve it.

반응형

'python-algorithm' 카테고리의 다른 글

leetcode 728. Self Dividing Numbers  (0) 2023.01.10
leetcode 2427. Number of Common Factors  (0) 2023.01.10
leetcode 2485. Find the Pivot Integer  (0) 2023.01.10
leetcode 2418. Sort the People  (0) 2023.01.09
leetcode 2315. Count Asterisks  (0) 2023.01.09

댓글