Why is this code not working? Please help for this One

Why is this code not working?


Please help for this One


Please refer to this code and tell me if you are able to understand it.

Don’t Understand this
temp = temp->next;
in first if

And Please tell the error in my code too.

temp-temp->next to move the current pointer to next node.
Try submitting both the codes on leetcode and get the test case your code gives wrong answer on. Dry run both the codes on it. You will find the error in your logic.

Thanks a lot Sir
I dry run on that
And My code was also correct except one error
p=c;
c=n;
I have written these in reverse.

And that passed many test cases
but stuck at [1] and k=1
And When I dry run, it is passing.

Please check the code which I sent you. You are not checking if head has the value k or not. If it has the value k, then it needs to be deleted and head has to be updated to the next node. Please refer to the code which I sent you.

Okay Sir, Even I have done that it’s still creating a lot of issues.
Much better to do with your code.

Sir How you thought about this Question, Like first having a general case and check it on edges too if it works or there is some issue .
Like that?

Its pretty much straightforward. You just have to delete nodes with value val. So there can be 3 possibilities - node can be head, it can be in between somewhere or it can be the last node.
So you just have to keep these three cases in mind and proceed.

Okayyy
I generally think about one case that is mid between
I should think about other test cases too.
Thanks.

Yes consider all cases carefully before solving. Welcome.

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.