728x90
반응형
첫번째 코드
단순하게 하나하나 돌아가면서 음수인 경우의 개수를 센다.
이때 list안에 list가 있는 형태이므로 이에 주의하여 인덱싱한다.
class Solution:
def countNegatives(self, grid: List[List[int]]) -> int:
answer = 0
for i in range(len(grid)):
for j in grid[i]:
if j < 0:
answer += 1
return answer
통과!
링크
https://github.com/ornni/leetcode/tree/main/1351-count-negative-numbers-in-a-sorted-matrix
leetcode/1351-count-negative-numbers-in-a-sorted-matrix at main · ornni/leetcode
Collection of LeetCode questions to ace the coding interview! - Created using [LeetHub v3](https://github.com/raphaelheinz/LeetHub-3.0) - ornni/leetcode
github.com
반응형
'코딩 테스트 > leetcode' 카테고리의 다른 글
Split a String in Balanced Strings (0) | 2024.06.22 |
---|---|
Find Words Containing Character (0) | 2024.06.21 |
Count Items Matching a Rule (0) | 2024.06.19 |
Find The Original Array of Prefix Xor (0) | 2024.06.18 |
Minimum Number of Moves to Seat Everyone (0) | 2024.06.17 |