• + 1 comment

    I think that the nested 'else if' wont be a much help in this case as the condition needs to be checked for all three 'if's in a case where A & B are not null. In case one of them is null it gets terminated without checking the remaining 'if's as it just simply returns a value. so I found no great optimization with nested 'else if' with this solution. Correct me if I am wrong. Happy coding.

    • + 1 comment

      You are right. We can just have:

      if(headA == NULL){
          return headB;
      } else if(headB == NULL){
          return headA;
      }
      
      • + 1 comment
        [deleted]
        • + 0 comments

          here is problem solution in python java c++ and c programming. https://solution.programmingoneonone.com/2020/07/hackerrank-merge-two-sorted-linked-lists-solution.html