일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 715. Range Module
- Python Code
- Python
- Python Implementation
- t1
- 운영체제
- 프로그래머스
- attribute
- Protocol
- 30. Substring with Concatenation of All Words
- shiba
- 109. Convert Sorted List to Binary Search Tree
- data science
- 밴픽
- Decorator
- LeetCode
- Regular Expression
- Class
- Substring with Concatenation of All Words
- kaggle
- Convert Sorted List to Binary Search Tree
- iterator
- 315. Count of Smaller Numbers After Self
- concurrency
- 파이썬
- DWG
- Generator
- 컴퓨터의 구조
- 시바견
- 43. Multiply Strings
Archives
- Today
- Total
Scribbling
LeetCode: 59. Spiral Matrix II 본문
class Solution:
def generateMatrix(self, n: int) -> List[List[int]]:
ret = [[0] * n for _ in range(n)]
num = 1
count = 0
y, x = count, count
while y < n:
y, x = count, count
i, j = y, x
for j in range(x, n):
ret[i][j] = num
num += 1
for i in range(y+1, n):
ret[i][j] = num
num += 1
for j in range(n-2, x-1, -1):
ret[i][j] = num
num += 1
for i in range(n-2, y, -1):
ret[i][j] = num
num += 1
count += 1
n -= 1
return ret
'Computer Science > Coding Test' 카테고리의 다른 글
LeetCode: 61. Rotate List (0) | 2021.09.24 |
---|---|
LeetCode: 60. Permutation Sequence (0) | 2021.09.24 |
LeetCode: 53. Maximum Subarray (0) | 2021.09.24 |
LeetCode: 57. Insert Interval (0) | 2021.09.24 |
LeetCode: 56. Merge Intervals (0) | 2021.09.23 |