Re: [闲聊] 每日LeetCode

楼主: Rushia (みけねこ的鼻屎)   2023-06-08 10:52:18
https://leetcode.com/problems/count-negative-numbers-in-a-sorted-matrix/description/
1351. Count Negative Numbers in a Sorted Matrix
给你一个排序好的 Matrix,找出该 Matrix 有几个非正整数。
Example 1:
Input: grid = [[4,3,2,-1],[3,2,1,-1],[1,1,-1,-2],[-1,-1,-2,-3]]
Output: 8
Explanation: There are 8 negatives number in the matrix.
Example 2:
Input: grid = [[3,2],[1,0]]
Output: 0
思路:
1.从每一列的最右边往左找,如果小于0 count就递增,否则跳出处理下一列。
Java Code:
作者: pandix (面包屌)   2023-06-08 11:22:00
这样跑到n^2了
作者: Che31128 (justjoke)   2023-06-08 11:47:00
这题遍寻有办法跑n吗
作者: NTHUlagka (拉卡)   2023-06-08 12:04:00
这题应该能O(min(m,n)) 因为他rows column都是有序的
楼主: Rushia (みけねこ的鼻屎)   2023-06-08 12:30:00
好像可以压 做的时候没想太多= =

Links booklink

Contact Us: admin [ a t ] ucptt.com