r/CodingHelp • u/waitingformsfs2020 • Feb 11 '22
[Ruby] program runs flawlessly in Vs code but when I try to submit on leetcode I am getting this error any idea?
26
u/marko312 Feb 11 '22
The given definition of TreeNode does not seem to contain a definition for a compact nor sort function. You'll likely have to implement these yourself.
17
2
u/Buttafuoco Feb 11 '22
Assuming compact exists in the passed in “root1” you want to make sure line 16 is within your get_all_elements function. You’ll need to indent it over. In Python white space matters. When you copied it over you likely lost some formatting
1
u/Its_Stev03 Feb 11 '22
This is Ruby, not python. I do not know how Ruby works and if indentation matters, but I would assume that indentation might be the problem.
1
u/Buttafuoco Feb 11 '22
Hahaa didn’t even see the while loop or notice the lack of colons after the method. Still should indent to express that these lines are included. This is the first time I’ve ever seen ruby wow
1
Feb 11 '22
Guys, this is so crazy?! I am going into my computer science degree next year and this is what I have to do?!
2
7
u/_McFuggin_ Feb 11 '22
It shouldn’t work in leet code. The TreeNode defined in leetcode has only left, right, and val attributes. So, you’ve got a handful of lines that are going to break. You won’t be able to use .compact, .length, or .sort