-
99클럽 코테 스터디 5일차 TIL: 배열, Leetcode 1476. Subrectangle QueriesToday_I_Learned/Algorithm 2024. 6. 15. 10:43
문제
https://leetcode.com/problems/subrectangle-queries/description/
통과 여부
Pass
나의 접근법
- 문제만 이해되면 풀이는 특별할 것 없이 단순했던 문제.
- 두 번째 Input 의 0번 요소로 2차원 List 인 self.rectangle 을 초기화
- updateSubrectangle(row1, col1, row2, col2, newValue) 는 2 중 for문을 돌려 self.rectangle[row1][col1] 부터 self.rectangle[row2][col2] 까지 newValue 로 초기화
- 문제는 해결되었지만, 코테가 이렇게 쉬울리 없다는 이상한 의심이 들어 더 빠른 방법이 있는 지 재도전 해 볼 예정이다.
class SubrectangleQueries: def __init__(self, rectangle: List[List[int]]): self.rectangle = rectangle def showRectangle(self): for i in range(len(self.rectangle)): print(self.rectangle[i]) def updateSubrectangle(self, row1: int, col1: int, row2: int, col2: int, newValue: int)-> None: for sx in range(row1, row2+1): for sy in range(col1, col2+1): self.rectangle[sx][sy] = newValue def getValue(self, row: int, col: int) -> int: return self.rectangle[row][col]
'Today_I_Learned > Algorithm' 카테고리의 다른 글
99클럽 코테 스터디 7일차 TIL: 배열, 1282. Group the People Given the Group Size They Belong To (0) 2024.06.17 99클럽 코테 스터디 6일차 TIL: 배열, LeetCode 2433. Find The Original Array of Prefix Xor (0) 2024.06.16 99클럽 코테 스터디 4일차 TIL : Graph, 프로그래머스, 순위 (0) 2024.06.13 99클럽 코테 스터디 3일차 TIL: Graph, Dijkstra, 프로그래머스, 가장 먼 노드 (0) 2024.06.12 99클럽 코테 스터디 1일차 : 그리디, 구명보트(프로그래머스) (0) 2024.06.06