Click here to Skip to main content
15,889,034 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
````
// this is a code
class Solution {
public:
    ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
        int carry = 0, first, second;
        ListNode *head = new ListNode(0), *tail = head;
        **while (l1 || l2 || carry)** {
            if (l1) {
                first = l1->val;
                l1 = l1->next;
            }
            else
                first = 0;
            
            if (l2) {
                second = l2->val;
                l2 = l2->next;
            }

> Blockquote

````


What I have tried:

thing is that i cant understand of WHILE lopp parameters
Posted
Updated 14-Dec-21 5:39am

1 solution

You understand OR, I assume?
a || b is true is either a, b, or both is true: it is only false if both a and b are both false.

And in C (and so C++) any non-zero value is true, so any valid link in l1 or l2 or carry will mean the loop goes around again.
 
Share this answer
 
Comments
Ramandeep Singh Dec2021 15-Dec-21 13:30pm    
thanks man for answering the question .I appreciate your help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900