由于这边的l1跟l2的长度可能不一样,所以说我们处理的时候呢就是说必须得遍历到它们俩都不为空为止,所以的话我们这里推荐一个用一个大的while循环,就是这里 classSolution {public://carry(进位),长度不一ListNode* addTwoNumbers(ListNode* l1, ListNode*l2) { ListNode* head =
You are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contain a single digit. Add the two numbers and return it as a linked list. You may assume the two numbers do not contain any lead...
LeetCode: Add Two Numbers 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) Out...
Java实现 1classSolution {2publicListNode addTwoNumbers(ListNode l1, ListNode l2) {3Stack<Integer> s1 =newStack<>();4Stack<Integer> s2 =newStack<>();5while(l1 !=null) {6s1.push(l1.val);7l1 =l1.next;8}9while(l2 !=null) {10s2.push(l2.val);11l2 =l2.next;12}13ListNode cur ...
(l1Num + " " + l2Num);StringsumString=sum+"";System.out.println(sumString);ListNodeemptyHead=newListNode(0);ListNodecurr=emptyHead;for(inti=sumString.length()-1;i>=0;i--){ListNodeNum=newListNode(Integer.valueOf(sumString.charAt(i)+""));curr.next=Num;curr=curr.next;}returnemptyHead...
*/classSolution{publicListNodeaddTwoNumbers(ListNode l1,ListNode l2){Stack<Integer>stack1=storeToStack(l1);Stack<Integer>stack2=storeToStack(l2);intcarry=0;Stack<ListNode>stack=newStack<ListNode>();while(!stack1.isEmpty()&&!stack2.isEmpty()){intval1=stack1.pop();intval2=stack2.pop();int...
The array-form of an integer num is an array representing its digits in left to right order. For example, for num = 1321, the array form is [1,3,2,1]. Given num, the array-form of an integer, and an integer k, return the array-form of the integer num + k. Example 1: Input...
13-roman-to-integer Time: 13 ms (31.15%), Space: 46.3 MB (47.79%) - LeetHub Aug 16, 2022 1329-sort-the-matrix-diagonally Time: 16 ms (28.13%), Space: 50.5 MB (13.72%) - LeetHub Aug 28, 2022 1338-reduce-array-size-to-the-half Time: 47 ms (81.36%), Space: 58.6 MB (89.17...
0004-Median-of-Two-Sorted-Arrays 0007-Reverse-Integer 0010-Regular-Expression-Matching 0011-Container-With-Most-Water 0012-Integer-to-Roman 0013-Roman-to-Integer 0014-Longest-Common-Prefix 0015-3Sum 0016-3Sum-Closest 0017-Letter-Combinations-of-a-Phone-Number 0018-4Sum 0019-Remo...
0;i < v.size();i++){ System.out.println(v.get(i)); } } } 2、Vector常用方法 void addElement...("one"); //加入的为integer的对象 v1.addElement(integer1); v1.addElement(integer1);...v1.addElement("two"); v1.addElement(new Integer(2)); v1.addElement(integer1);...v1...