第四章 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...
leetcode Add Two Numbers(对指针的一些基本操作) 1ListNode *ptr,*l;2l =newListNode(0);//这才是正确的赋值姿势3ptr = l;//赋给的是地址4intup =0,fg1 =0,fg2 =0;5//cout<<"r"<<endl;6while(1)7{8if(fg1 && fg2)break;9inta,b;10if(fg1) a =0;11elsea = l1 ->val;12if(fg2...
classSolution(object): def addTwoNumbers(self, l1, l2): l3= ListNode(0) current=l3 carry=0whilel1 or l2: #1,1| None,1|1,None # Pad0ifNoneifl1isNone: l1v=0else: l1v=l1.valifl2isNone: l2v=0else: l2v=l2.val # Sum tmp= l1v + l2v +carryiftmp >=10: x= tmp%10carry=...
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 考查...
LeetCode:Add Two Numbers ,这个进位放到前面标记的第3位上,同时把第4位和第5位置0,标记第6位为下一次进位标志 第7位同上 所以综上所述,从高位往低位计算加法时,规则是: 一、如果当前位没有进位:(1)如果当前位的和小于9,则...进位放到第0位;同时标记第1位为下一次的进位标志 第2位相加,结果为3,不需...
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...
/// Source : https://leetcode.com/problems/add-to-array-form-of-integer/ /// Author : liuyubobobo /// Time : 2019-02-13 #include <iostream> #include <vector> using namespace std; /// Array and number addition /// Time Complexity: O(n) /// Space Complexity: O(...
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....
921. Minimum Add to Make Parentheses Valid # 题目 # Given a string S of ‘(’ and ‘)’ parentheses, we add the minimum number of parentheses ( ‘(’ or ‘)’, and in any positions ) so that the resulting parentheses string is valid. Formally, a parent
LeetCode 445 Add Two Numbers II 445-Add Two Numbers II You are given two linked lists representing two non-negative numbers. 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....