I ran into a problem that I've never run into in the past. It was soo weird. I feel like I should have run into this issue before, but I haven't. The problem I ran into was scopes, local and global variables. The solution to the leetcode I was solving consisted of a nested function. In that nested function, I attempted to modify a variable in the outer function, but It didn't work. Lots of leetcode problems ask for this so I was so stumped as to why there was an error getting thrown now.
Heres what Im talking about:
Theres a couple fixes to this. The one I chose was to specify the variable at the top with nonlocal. I could have also used the keyword global. That would have worked. ORRRR I could have specified in the outer function this.diam = 0 instead of diam = 0. the keyword This shows that it is a parameter of the object.Super weird small issue I ran into. Other than that, Leetcode went gracefully today. Happy with my results!!!!!!
No comments:
Post a Comment