| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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
- English
- 링피트
- 사이드
- 화상영어
- 영어원서읽기
- FIT XR
- 30분
- 읽기
- 10분
- 개발자
- 리얼 클래스
- Writing
- 뭐든
- 스탭퍼
- leetcode
- realclass
- Daily Challenge
- 영어공부
- 월간
- 미드시청
- 괜찮음
- 잡생각
- 파비최
- 쓰릴오브파이트
- 프로젝트
- 만화도
- 운동
- 매일
- Problem Solving
- 3줄정리
Archives
- Today
- Total
파비의 매일매일 공부기록
Today's Challenge 본문
https://leetcode.com/problems/search-a-2d-matrix-ii/
Search a 2D Matrix II - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
오랫만에 내 손으로 풀어봄.
무식하게 x 축으로 한번 쭉 순회하고, y 축으로 한번 쭉 순회하면 된다.
class Solution:
def searchMatrix(self, matrix: List[List[int]], target: int) -> bool:
found = False
xmax, ymax = -(10**9) - 1, -(10**9) - 1
for y in range(len(matrix)):
for x in range(len(matrix[0])):
if matrix[y][x] == target:
found = True
xmax = xmax if xmax > matrix[y][x] else matrix[y][x]
if x == 0:
continue
if matrix[y][x-1] > matrix[y][x]:
return False
for x in range(len(matrix[0])):
for y in range(len(matrix)):
ymax = ymax if ymax > matrix[y][x] else matrix[y][x]
if y == 0:
continue
if matrix[y-1][x] > matrix[y][x]:
return False
return found반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
| Today's Challenge (0) | 2022.07.26 |
|---|---|
| Today's Challenge (0) | 2022.07.25 |
| Today's Challenge (0) | 2022.07.23 |
| Today's Challenge (0) | 2022.07.22 |
| Today's Challenge (0) | 2022.07.21 |
Comments