point1->val< 9的判断成功的次数有点多啊,不知道有没有优化的方法。 ListNode *addTwoNumbers(ListNode *l1, ListNode *l2){if(l1 ==NULL)returnl2;if(l2 ==NULL)returnl1;intlen1 =0;intlen2 =0;for(ListNode *p = l1; p !=NULL; p = p->next) ++len1;for(ListNode *p = l2; p !=NULL...
网上的代码:https://discuss.leetcode.com/topic/65279/easy-o-n-java-solution-using-stack,最后几步指针没有看懂,使用stack也就是为了先计算靠右的数字,没有看懂的部分可可以用字符串来实现
LeetCode:Add Two Numbers ,这个进位放到前面标记的第3位上,同时把第4位和第5位置0,标记第6位为下一次进位标志 第7位同上 所以综上所述,从高位往低位计算加法时,规则是: 一、如果当前位没有进位:(1)如果当前位的和小于9,则...进位放到第0位;同时标记第1位为下一次的进位标志 第2位相加,结果为3,不需...
第四章 LeetCode 题解 0001~0099 0001. Two Sum 0002. Add Two Numbers 0003. Longest Substring Without Repeating Characters 0004. Median of Two Sorted Arrays 0005. Longest Palindromic Substring 0006. Zig Zag Conversion 0007. Reverse Integer 0008. String to Integer Atoi 0009. Palindrome Number 0011...
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) ...
0004-median-of-two-sorted-arrays.py 0005-longest-palindromic-substring.py 0007-reverse-integer.py 0010-regular-expression-matching.py 0011-container-with-most-water.py 0012-integer-to-roman.py 0013-roman-to-integer.py 0014-longest-common-prefix.py 0015-3sum.py 0017-lette...
0977-Squares-of-a-Sorted-Arrays 0978-Longest-Turbulent-Subarray 0979-Distribute-Coins-in-Binary-Tree 0980-Unique-Paths-III 0981-Time-Based-Key-Value-Store 0982-Triples-with-Bitwise-AND-Equal-To-Zero 0983-Minimum-Cost-For-Tickets 0984-String-Without-AAA-or-BBB 0985-Sum-of-Even-...
LeetCode之Add Digits 1、题目 Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. For example: Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one digit, return it....
Optimized? 可以用Arrays.sort对words进行排序,结果就是字典序。然后利用一个辅助的Set来解? 或者利用Trie?
package leetcode func minAddToMakeValid(S string) int { if len(S) == 0 { return 0 } stack := make([]rune, 0) for _, v := range S { if v == '(' { stack = append(stack, v) } else if (v == ')') && len(stack) > 0 && stack[len(stack)-1] == '(' { sta...