Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to realize two linked lists by Java

Shulou Source: shulou.com Published: 2022-05-31 17:55:50 10月28日 Update

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

Tags: Pointer two content more knowledge node practical successful next dilemma reality situation article case result editing website industry process high quality Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS OPPO Reno Shulou Technology Huawei Xiaomi