当前位置:网站首页>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
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/
边栏推荐
- 获取屏幕高度
- 什么是产品思维
- P4 learning - Basic tunneling
- 双链表:初始化 插入 删除 遍历
- Redis - cache penetration, cache breakdown, cache avalanche
- C WinForm program interface optimization example
- What is product thinking
- Deployment of mini version message queue based on redis6.0
- Chapter 53 overall understanding of procedures from the perspective of business logic implementation
- The principle of journal node
猜你喜欢
Exercises on recursion in C language
2022-2028 global single travel industry research and trend analysis report
What if the disk of datanode is full?
剑指 Offer 18. 删除链表的节点
Can JDBC based on openjdk connect to MySQL?
Member management applet actual development 07 page Jump
Oracle-数据完整性
初识 Flutter 的绘图组件 — CustomPaint
2022-2028 global ICT test probe industry research and trend analysis report
第53章 从业务逻辑实现角度整体性理解程序
随机推荐
Cmu15445 (fall 2019) project 1 - buffer pool details
对libco的一点看法
Docsify building a personal minimalist knowledge warehouse
Get screen height
什么是产品思维
20220215 misc buctf easycap Wireshark tracks TCP flow hidden key (use of WinHex tool)
Chapter 53 overall understanding of procedures from the perspective of business logic implementation
PyTorch安装并使用gpu加速
SAP ui5 beginner tutorial 19 - SAP ui5 data types and complex data binding
NE555波形发生器手把手教程之NE555内部结构(一)
HDU 2488 A Knight's Journey(DFS)
PHP online confusion encryption tutorial sharing + basically no solution
20220215-ctf-misc-buuctf-einstein-binwalk analyze picture-dd command separate zip file -- look for password in picture attribute
Mindjet mindmanager2022 mind map decompression installer tutorial
ArrayList analysis 1-cycle, capacity expansion, version
2022-2028 global mobile scanning radiology room industry survey and trend analysis report
Solving the weird problem that the query conditions affect the value of query fields in MySQL query
Redis - cache penetration, cache breakdown, cache avalanche
C language file operation for conquering C language
MySQL storage engine