当前位置:网站首页>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/
边栏推荐
- 女朋友说:你要搞懂了MySQL三大日志,我就让你嘿嘿嘿!
- Vulnerability discovery - App application vulnerability probe type utilization and repair
- 2022-2028 global retro glass industry research and trend analysis report
- 2022-2028 global ICT test probe industry research and trend analysis report
- NE555 waveform generator handle tutorial NE555 internal structure (I)
- Two-stage RO: part 1
- Error msb8031: building an MFC project for a non Unicode character set is deprecated
- 剑指 Offer 19. 正则表达式匹配
- 2022-2028 global ultra high purity electrolytic iron sheet industry research and trend analysis report
- Introduction to ES6 promise, new features of ES7 and es8 async and await
猜你喜欢

C#生成putty格式的ppk文件(支持passphrase)

The quantity and quality of the devil's cold rice 101; Employee management; College entrance examination voluntary filling; Game architecture design

写给 5000 粉丝的一封信!

20220215 CTF misc buuctf Xiaoming's safe binwalk analysis DD command separate rar file archpr brute force password cracking

2022-2028 global PTFE lined valve industry research and trend analysis report

2022-2028 global 3D printing ASA consumables industry research and trend analysis report

初识 Flutter 的绘图组件 — CustomPaint

Implementation of OSD on Hisilicon platform (1)

【原创】 PLSQL 索引排序优化

2022-2028 global encrypted external hard disk industry research and trend analysis report
随机推荐
What is the fastest way to import data from HDFS to Clickhouse? Spark is imported through JDBC or HDFS
Error 2059 when Navicat connects to MySQL
2022-2028 global rampant travel industry research and trend analysis report
Error msb8031: building an MFC project for a non Unicode character set is deprecated
Vulnerability discovery - App application vulnerability probe type utilization and repair
Basic data structure of redis
Host FL Studio fruit music production daw20.9
Luogu p1144 shortest circuit count
解决 error MSB8031: Building an MFC project for a non-Unicode character set is deprecated.
C language file operation for conquering C language
Confirm() method of window
Redis - cache penetration, cache breakdown, cache avalanche
剑指 Offer 19. 正则表达式匹配
Redis - understand the master-slave replication mechanism
[daily record] - bug encountered in BigDecimal division operation
初识 Flutter 的绘图组件 — CustomPaint
2022-2028 global single travel industry research and trend analysis report
Get to know the drawing component of flutter - custompaint
2022-2028 global encrypted external hard disk industry research and trend analysis report
Introduction to ES6 promise, new features of ES7 and es8 async and await