Spiral Matrix II - Leetcode 59 - Python

preview_player
Показать описание

Solving Spiral Matrix II - Leetcode 59, today's daily leetcode problem on May 9th.

0:00 - Read the problem
1:40 - Drawing Explanation
9:30 - Coding Explanation

leetcode 59

#neetcode #leetcode #python
Рекомендации по теме
Комментарии
Автор

Two is easier than one because it’s easy to forget to recheck the left / right and top / bottom conditions half way through the main loop due to rectangular cases

def__init
Автор

We can use a circular linked list of pairs with the directions like this (1, 0), (0, 1), (-1, 0), (0, -1) each time the value we are at satisfies this value - 1% N-1 == 0 we advance our list add the pair to row and col values, value++ and terminate the loop when value == n^2, instead of 4 pointers we have a list of 4 direction pairs, the reminder operation left hand side will decrease by 1 each 3 direction changes

deadlyecho
Автор

this is splendid, i catch the fire immediately after watching your vid. thanks a lot!

归嶋
Автор

Thank you for the daily leetcode problems.

MP-nyep
Автор

does this code work for anybody here, I am getting an error "IndexError: list assignment index out of range" Can anybody explain what is happening

sanjeevmurmu
Автор

Hey man I am poor can you give me advice

masternobody
welcome to shbcf.ru