일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- 만화도
- 읽기
- 뭐든
- leetcode
- realclass
- 10분
- 월간
- 30분
- English
- 영어공부
- 리얼 클래스
- 화상영어
- 사이드
- 개발자
- FIT XR
- Problem Solving
- Daily Challenge
- 파비최
- 스탭퍼
- 미드시청
- 프로젝트
- 링피트
- 영어원서읽기
- 잡생각
- Writing
- 괜찮음
- 쓰릴오브파이트
- 매일
- 운동
- 3줄정리
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.11.23 Today's Challenge 본문
https://leetcode.com/problems/diagonal-traverse-ii/
Diagonal Traverse II - LeetCode
Can you solve this real interview question? Diagonal Traverse II - Given a 2D integer array nums, return all elements of nums in diagonal order as shown in the below images. Example 1: [https://assets.leetcode.com/uploads/2020/04/08/sample_1_1784.png] I
leetcode.com
class Solution:
def findDiagonalOrder(self, nums: List[List[int]]) -> List[int]:
groups = defaultdict(list)
for row in range(len(nums)-1, -1, -1):
for col in range(len (nums[row])):
diagonal = row + col
groups[diagonal].append(nums[row][col])
ans, curr = [], 0
while curr in groups:
ans.extend(groups[curr])
curr += 1
return ans
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
2023.11.25 Today's Challenge (2) | 2023.11.25 |
---|---|
2023.11.24 Today's Challenge (1) | 2023.11.24 |
2023.11.22 Today's Challenge (0) | 2023.11.22 |
2023.11.21 Today's Challenge (0) | 2023.11.21 |
2023.11.20 Today's Challenge (1) | 2023.11.20 |
Comments