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

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -