0

Can anyone tell me why I'm getting an error "Terminated Execution Timed out"?

https://code.sololearn.com/c6m6XwpGF79V/?ref=app

24th Oct 2020, 11:02 AM
Prit
Prit - avatar
2 Respostas
+ 1
(1)(EDITED) When head is null you assign data to head. You don't need to use new Node but assign data to data in the node and do that for the others. Also, the method should end right there since you've already add data to an element. Add a return statement to end the method. (2) I suggest you use StringBuilder instead of String for concatenation. It's a lot faster. But remember to use append() instead of += and use output.toString() at the return statement. (3) Use while(currentnode != null) instead of next. This avoid the last element is not printed. (4) Use currentnode.data instead of next in string concatenation. Node itself doesn't have toString() therefore can't be used.
24th Oct 2020, 11:21 AM
你知道規則,我也是
你知道規則,我也是 - avatar