Remove Element 移除元素 102 -- 15:04 App [LeetCode] 71. Simplify Path 简化路径 23 -- 9:03 App [LeetCode] 16. 3Sum Closest 最接近的三数之和 20 -- 13:44 App [LeetCode] 15. 3Sum 三数之和 26 -- 15:53 App [LeetCode] 12. Integer to Roman 整数转罗马数字 ...
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...
由于这边的l1跟l2的长度可能不一样,所以说我们处理的时候呢就是说必须得遍历到它们俩都不为空为止,所以的话我们这里推荐一个用一个大的while循环,就是这里 classSolution {public://carry(进位),长度不一ListNode* addTwoNumbers(ListNode* l1, ListNode*l2) { ListNode* head =newListNode(-1);//哨兵//ListN...
leetcode2变式,2题是高位在后,现在是高位在前节点 You are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list. You may assume ...
Reverse Integer 整数反转 192023-10 5 [LeetCode] 6. ZigZag Conversion 之字形变换 222023-10 6 [LeetCode] 5. 最长回文子串 212023-10 7 [LeetCode] 4. 寻找两个正序数组的中位数 272023-10 8 [LeetCode] 3. 无重复字符的最长子串 222023-10 9 [LeetCode] 2. Add Two Numbers 两个数字相加 ...
两数相加II。这题思路跟[LeetCode] 2. Add Two Numbers很相似。唯一的不同点在于,第2题是从最低位到最高位做加法,只要记得进位即可;但是445是在逆向做加法,linked list的头结点是数字的最高位,先reverse两个list然后再做加法的思路会略显麻烦。如下这个例子实际是在算7243 + 564 = 7807 ...
publicint[]twoSum(int[]nums,inttarget){HashMap<Integer,Integer>map=newHashMap<>();for(inti=0;i<nums.length;i++){if(map.containsKey(target-nums[i])){returnnewint[]{map.get(target-nums[i]),i};}map.put(nums[i],i);}returnnull;}...
(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...
public ListNode addTwoNumbers(ListNode l1, ListNode l2) { Stack<Integer> s1 = new Stack<Integer>(); Stack<Integer> s2 = new Stack<Integer>(); while(l1 != null) { s1.push(l1.val); l1 = l1.next; }; while(l2 != null) { ...
FindHeaderBarSize FindTabBarSize FindBorderBarSize Given two binary stringsaandb, returntheir sum as a binary string. Example 1: Input:a = "11", b = "1"Output:"100" Example 2: Input:a = "1010", b = "1011"Output:"10101" Constraints:...