프로그램 개발/미분류
[LeetCode/Python]Array and String - Spiral Matrix
(ㅇㅅㅎ)
2020. 8. 24. 13:26
728x90
반응형
문제
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.
입력받은 배열을 다음과 같이 배열로 만들어서 출력합니다.
코드를 보시려면 더보기를 클릭해 주세요.
더보기
파이썬 코드
class Solution:
def spiralOrder(self, matrix: List[List[int]]) -> List[int]:
tmp = matrix.copy()
answer = []
while len(tmp) != 0:
answer.extend(tmp[0])
tmp.remove(tmp[0])
tmp = list(map(list, zip(*tmp)))[::-1]
return answer
|
유사한 문제입니다.
https://onlab94.tistory.com/32
[python]Make a spiral
https://www.codewars.com/kata/534e01fbbb17187c7e0000c6/train/python Codewars: Train your coding skills Codewars is where developers achieve code mastery through challenge. Train on kata in the dojo..
onlab94.tistory.com
반응형