IndexOutOfRangeException? Why??
I am analysing a solution for Spiral Matrix puzzle on LeetCode: https://leetcode.com/problems/spiral-matrix/
But I keep getting an IndexOutOfRange exception at this line
if (x >= r && !bol[y, x])
Could anyone kindly tell me why? Here is the whole solution code
`LeetCode
LeetCode - The World's Leading Online Programming Learning Platform
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
2 Replies
This code is way too complex and unreadable to get a proper answer
The best solution here is to improve the readability of the code, and possible placing
Debug.Assert
statements to check if variables are what they should be
Currently you have multiple actions happening in a single method and these should be split up. You should also name your variables better and not reuse everything constantly.
Debugging this takes way too much time because you need to find out the behaviour of the whole method before anything can be determined, so you should improve the way you write itThank you so much for your assessment of this code. Someone else wrote it so it's good for me to know it's way too complex and needs to be split up. I still don't have a good set of eyes to distinguish the clean code from not so clean ones