In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "how to return Java to the first node". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to get Java back to the first node"!
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list. Input: (2-> 4-> 3) + (5-> 6-> 4) Output: 7-> 0-> 8 Definition for singly-linked list. * public class ListNode {* int val; * ListNode next; * ListNode (int x) {val = x;} *} * / public class AddTwoNumbers {public static void main (String [] args) {ListNode L1 = new ListNode (2); ListNode l1n1 = new ListNode (4); ListNode l1n2 = new ListNode (3); ListNode L2 = new ListNode (5); ListNode l2n1 = new ListNode (6) ListNode l2n2 = new ListNode (4); l1.next = 11n1; l1n1.next = L1N2; l2.next = L2N1; l2n1.next = L2N2; AddTwoNumbers atn = new AddTwoNumbers (); ListNode pre = atn.addTwoNumbers (L1SCH L2); Utils.print (pre);} public ListNode addTwoNumbers (ListNode L1, ListNode L2) {int carry = 0; ListNode newHead = new ListNode (0) / / as ListNode p1 = L1, p2 = L2, p3 newhead; / / p3 as operation variable while (p1! = null | | p2! = null) {if (p1! = null) {carry + = p1.vale; p1 = p1.nextt;} if (p2! = null) {carry + = p2.val P2 = p2.next;} p3.next=new ListNode (carry); p3 = p3.next; carry / = 10;} if (carry==1) p3.next=new ListNode (1); return newHead.next / / return to the first node}} so far, I believe you have a deeper understanding of "how to return the Java to the first node". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.