c++ - Leetcode - time limit exceeded -
the problem asking reverse singly linked list this, input is:
1->2->3->4
the output after function should be:
4->3->2->1
i wrote simple recursion solve problem shows time limit exceeded.
listnode* reverse(listnode* &curr){ if(curr->next==null){ return curr; } return reverse(curr->next)->next = curr; }
the definition of listnode is:
struct listnode { int val; listnode *next; listnode(int x) : val(x), next(null) {}};
thanks help!
Comments
Post a Comment