How to realize two linked lists by Java
This article introduces the relevant knowledge of "how to achieve two linked lists in Java". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
/ * Definition for singly-linked list. * public class ListNode {* int val; * ListNode next; * ListNode (int x) {val = x;} *} * / public class Solution {public ListNode mergeTwoLists (ListNode L1, ListNode L2) {if (L1 = = null) return L2; if (L2 = = null) return L1; ListNode head = null; ListNode end = null; ListNode first = L1; / / first linked list ListNode second = L2 / / the second linked list while (first! = null & & second! = null) {int tmp1 = first.val; int tmp2 = second.val; if (tmp1