일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 잡생각
- 미드시청
- Problem Solving
- 화상영어
- 프로젝트
- 영어공부
- 스탭퍼
- 읽기
- 10분
- 리얼 클래스
- English
- 개발자
- 괜찮음
- FIT XR
- leetcode
- 월간
- 쓰릴오브파이트
- Daily Challenge
- 매일
- 뭐든
- 영어원서읽기
- 3줄정리
- 만화도
- 운동
- realclass
- 파비최
- Writing
- 사이드
- 링피트
- 30분
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.12.14 Today's Challenge 본문
https://leetcode.com/problems/special-positions-in-a-binary-matrix/
Special Positions in a Binary Matrix - LeetCode
Can you solve this real interview question? Special Positions in a Binary Matrix - Given an m x n binary matrix mat, return the number of special positions in mat. A position (i, j) is called special if mat[i][j] == 1 and all other elements in row i and co
leetcode.com
압축해서 count 하는 식으로 판단하면 됨
class Solution:
def numSpecial(self, mat: List[List[int]]) -> int:
m, n = len(mat), len(mat[0])
r_cnt, c_cnt = [0]*m, [0]*n
for r in range(m):
for c in range(n):
if mat[r][c] == 1:
r_cnt[r] += 1
c_cnt[c] += 1
ans = 0
for r in range(m):
for c in range(n):
if mat[r][c] == 1:
if r_cnt[r] == 1 and c_cnt[c] == 1:
ans += 1
return ans
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
2023.12.16 Today's Challenge (1) | 2023.12.16 |
---|---|
2023.12.15 Today's Challenge (0) | 2023.12.15 |
2023.12.13 Today's Challenge (0) | 2023.12.13 |
2023.12.12 Today's Challenge (0) | 2023.12.12 |
2023.12.11 Today's Challenge (0) | 2023.12.11 |
Comments