This code is showing error for 1 2 3 4 5
As I am giving the op as 3 2 1 5 4 with k=3
and it is expecting 3 2 1 4 5
Please tell how to do that.
And Also tell if any video available from where I can see the detailed explanation of this Question.
This code is showing error for 1 2 3 4 5
As I am giving the op as 3 2 1 5 4 with k=3
and it is expecting 3 2 1 4 5
Please tell how to do that.
And Also tell if any video available from where I can see the detailed explanation of this Question.
Hey @cbcao263
You only have to reverse when k nodes are present so add this lines and you are good to go :
int count=0; ListNode*temp=head; while(temp && count<k){ temp=temp->next; count++; } if(count<k)return head; count=0;
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.
Thanks Sir, for both.