当前位置:网站首页>Day31-t1380-2022-02-15-not answer by yourself

Day31-t1380-2022-02-15-not answer by yourself

2022-07-01 01:03:00 Parchment

1380 The lucky number in the matrix
To give you one m * n Matrix , The number in the matrix Each are not identical . Please press arbitrarily Return all the lucky numbers in the matrix in order .

Lucky number refers to the elements in the matrix that meet the following two conditions at the same time :

The smallest of all elements in the same row The largest of all elements in the same column

source : Power button (LeetCode)
link :https://leetcode-cn.com/problems/lucky-numbers-in-a-matrix

class Solution:
    def luckyNumbers(self, matrix: List[List[int]]) -> List[int]:
        ans = []
        for row in matrix:
            for j, x in enumerate(row):
                if max(r[j] for r in matrix) <= x <= min(row):
                    ans.append(x)
        return ans

#  author :LeetCode-Solution
#  link :https://leetcode-cn.com/problems/lucky-numbers-in-a-matrix/solution/ju-zhen-zhong-de-xing-yun-shu-by-leetcode-solution/

995 K The minimum number of turns for consecutive bits
Given a binary array nums And an integer k .

k Bit flip It's from nums Select a length of k Of Subarray , At the same time, each of the subarrays 0 Such as 1 , Take each of the subarrays 1 Such as 0.

The returned array does not exist 0 The minimum required k Bit flip frequency . If not , Then return to -1 .

Subarray It's an array of continuity part .

source : Power button (LeetCode)
link :https://leetcode-cn.com/problems/minimum-number-of-k-consecutive-bit-flips

 Please add a picture description

class Solution(object):
    def minKBitFlips(self, A, K):
        """ :type A: List[int] :type K: int :rtype: int """
        N = len(A)
        que = collections.deque()
        res = 0
        for i in range(N):
            if que and i >= que[0] + K:
                que.popleft()
            if len(que) % 2 == A[i]:
                if i +  K > N: return -1
                que.append(i)
                res += 1
        return res

#  author :fuxuemingzhu
#  link :https://leetcode-cn.com/problems/minimum-number-of-k-consecutive-bit-flips/solution/hua-dong-chuang-kou-shi-ben-ti-zui-rong-z403l/
原网站

版权声明
本文为[Parchment]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202160404227764.html