05 2020 档案
摘要:给定一个字符串,表示一串文件路径,其中 '.','/' 可以跳过,'..' 表示返回上一层路径,输出最终的路径。 Input: "/a/./b/../../c/"Output: "/c" Input: "/home//foo/"Output: "/home/foo"Explanation: In t
阅读全文
摘要:给定一个矩阵,矩阵中的元素表示成本,求,从矩阵左上角到右下角最小的成本路线,每一次只能向右或者向下走。 Input:[ [1,3,1], [1,5,1], [4,2,1]]Output: 7Explanation: Because the path 1→3→1→1→1 minimizes the s
阅读全文
摘要:给定一个矩阵,矩阵元素由0/1组成,0表示可以通过,1表示有障碍,不能通过,且每次只能向右走或者向下走,求从矩阵左上角走到矩阵右下角的路线条数。 Input:[ [0,0,0], [0,1,0], [0,0,0]]Output: 2Explanation:There is one obstacle
阅读全文
摘要:给定2个正整数 m, n ,表示长和宽,求从左上角到右下角的路线条数,每次只能向右走或者向下走。 Input: m = 7, n = 3Output: 28 思路:一、利用递归思想,但是提交OJ,显示运行超时,不能AC。 class Solution { public: int uniquePath
阅读全文
摘要:给定一个单链表,以及一个非负整数 k ,求将此链表循环右移 k 个单个后的新链表。 Input: 1->2->3->4->5->NULL, k = 2Output: 4->5->1->2->3->NULLExplanation:rotate 1 steps to the right: 5->1->2
阅读全文
摘要:给定一个正整数 n ,从 1 ~ n 的数全排列,共有 n! 种排列方法,求出其中的第 k 个排列。 Input: n = 3, k = 3Output: "213" 思路:这题跟 46 很像,一开始也采用 46题的方法,但是输出来的顺序不对。 错误的解法: class Solution { pub
阅读全文
摘要:给定一个正整数,要求,输出一个螺旋状的 n*n 二维矩阵,元素从 1 ~ n*n 的值按螺旋顺序排列。 Input: 3Output:[ [ 1, 2, 3 ], [ 8, 9, 4 ], [ 7, 6, 5 ]] 思路:一、此题跟54题十分类似,基本就是在54题的基础上稍微变换。使用坐标顺序写入的
阅读全文
摘要:给定一个数组的容器,将容器中的数组代表一个区间,如果有区间重叠的,将他们融合为一个大的区间,输出最终的区间。 Example 1:Input: [[1,3],[2,6],[8,10],[15,18]]Output: [[1,6],[8,10],[15,18]]Explanation: Since i
阅读全文
摘要:给定一个数组,数组中的数字,代表当前元素的最大跳转值,可以不用跳转到最大的跳转值,比如下标 0 的值为3,可以跳转到下标 1,2,3均可,求,是否能跳转到最后一个下标。 Input: nums = [2,3,1,1,4]Output: trueExplanation: Jump 1 step fro
阅读全文
摘要:给定一个二维数组,将数组中的元素按照螺旋顺序输出,顺时针螺旋。 Input:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]Output: [1,2,3,6,9,8,7,4,5] 思路:使用迷宫遍历,设定寻路的方向,当碰壁了,就换到下一个方向,但是要将已经走过的点标记
阅读全文
摘要:给定一个浮点数a,一个整数b,求a的b次幂。 Input: 2.00000, 10Output: 1024.00000 Input: 2.00000, -2Output: 0.25000Explanation: 2-2 = 1/22 = 1/4 = 0.25 思路:如果运用头文件的话,一行代码:po
阅读全文
摘要:给定一个字符串容器,对这些字符串进行分类,是字符的分为一类,返回分类结果。 Input: ["eat", "tea", "tan", "ate", "nat", "bat"],Output:[ ["ate","eat","tea"], ["nat","tan"], ["bat"]] 思路:暴力法,此
阅读全文
摘要:给定一个二维方阵,求,将此方阵顺时针旋转90度。就地交换,不引入额外的存储消耗。 Given input matrix =[ [ 5, 1, 9,11], [ 2, 4, 8,10], [13, 3, 6, 7], [15,14,12,16]], rotate the input matrix in
阅读全文
摘要:给定一个数组,数组中的元素有重复项,将其全排列,求出全排列的组合。 Input: [1,1,2]Output:[ [1,1,2], [1,2,1], [2,1,1]] 思路:和46题很相似,但难度比46题更大,如果不使用 set 去重的话,很难做出来。将46题的方法简单去重,再使用set,即可。 c
阅读全文
摘要:给定一个数组,数组中的元素不重复,将数组中的元素全排列,输出全排列的组合。 Input: [1,2,3]Output:[ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1]] 思路:(回溯 + 深度优先搜索)利用递归,将数组的下标元素不断的交换,
阅读全文
摘要:给定两个字符串,都有数字组成,求这两个字符串所表示的数字的乘积,返回字符串表示形式。两个字符串的长度 < 110. 除了数字0本身,没有前导0存在。 Input: num1 = "123", num2 = "456"Output: "56088" 思路:一、由于字符串表示的数很大,几十上百位,肯定不
阅读全文
摘要:给定一个数组,给定一个目标值,求数组中的元素之和等于目标值的组合。数组中的元素不能重复使用,但数组中有重复的元素。 Input: candidates = [10,1,2,7,6,1,5], target = 8,A solution set is:[ [1, 7], [1, 2, 5], [2,
阅读全文
摘要:给定一个数组,和一个目标值,求出用数组中的元素相加之和等于目标值得组合,数组中的数可以重复利用。 Input: candidates = [2,3,5], target = 8,A solution set is:[ [2,2,2,2], [2,3,3], [3,5]] 思路:由于数组中的元素可以重
阅读全文
摘要:给定一个9*9的二维数组,求里面的数字要求横排9个、竖排9个,3*3的各自组成的9个,都组成不重复的数字。Input:[ ["5","3",".",".","7",".",".",".","."], ["6",".",".","1","9","5",".",".&quo
阅读全文
摘要:给定一个升序排列的数组,以及一个整数,查找这个整数在数组中出现的起始、终止下标。没找到就返回 [-1,-1]。要求O(logn)时间复杂度。 Input: nums = [5,7,7,8,8,10], target = 8Output: [3,4] 思路: 运用二分查找,当找到与目标相等的下标时,
阅读全文
摘要:给定一个已排好序的数组,将数组循环移动后,给定一个目标整数,求目标整数是否在数组中,若在,返回下标,否则,返回 -1 ,必须使用 O(logn)时间复杂度。Input: nums = [4,5,6,7,0,1,2], target = 0Output: 4 思路:题目要求O(logn)的时间复杂
阅读全文
摘要:给定一个数组,将里面的数字找到比当前排列大一个的下一个排列。如果找不到,则返回最小值排列。1,2,3 → 1,3,23,2,1 → 1,2,31,1,5 → 1,5,1 注意:是找比当前排列大的下一个排列,并不是找最大的排列。 思路:规律还是比较好找的,从后往前看,如果是:54321. 这种表示已经
阅读全文
摘要:给定两个int整数,分别为被除数和除数,要求不用乘除、取模,得到商的整数值。对于溢出时,int最大的边界值。Input: dividend = 10, divisor = 3Output: 3Explanation: 10/3 = truncate(3.33333..) = 3. 思路:先得到商的符
阅读全文
摘要:给定一个链表,从头开始,将其相邻的2个节点翻转。Given 1->2->3->4, you should return the list as 2->1->4->3. 思路:用一个临时节点tmp_head,先指向当前头结点head的下一个节点,然后移动临时节点,再指向当前头结点,再移动头节点。需要注
阅读全文
摘要:给定一个整数n,包含 n个左括号和 n个右括号,将这n对括号组成有效的符号类型。For example, given n = 3, a solution set is:[ "((()))", "(()())", "(())()", "()(())", "()()()"] 思路来源,Grandyang
阅读全文
摘要:给定一个链表和一个数字n,将链表上倒数第n个节点删掉。Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the linked list becomes 1->2->3->
阅读全文
摘要:给定一个数组和一个目标数字,求数组中的4个元素之和等于目标数字,输出这4个数字所有可能的组合。 Given array nums = [1, 0, -1, 0, -2, 2], and target = 0. A solution set is:[ [-1, 0, 0, 1], [-2, -1, 1
阅读全文
摘要:给定一个值为 2~ 9 的字符串,每个数字如下所示,输出所有可能的组合结果。 Input: "23"Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"]. 思路:一开始没读懂题意,以为是两两结合,其实是所有数字一起的组合。比如“
阅读全文
摘要:给定一个数组和一个目标数,求数组中的任意三个元素之和,与目标数最接近,返回和值。 Given array nums = [-1, 2, 1, -4], and target = 1. The sum that is closest to the target is 2. (-1 + 2 + 1 =
阅读全文
摘要:给定一个无序数组,求数组中满足三个元素之和 = 0 的答案。Given array nums = [-1, 0, 1, 2, -1, -4], A solution set is:[ [-1, 0, 1], [-1, -1, 2]] 思路:由于数组是无序的所以先将其排成有序的数组,利用一个 for
阅读全文
摘要:给定一个 1 ~ 3999 的整数,求得其罗马数字的表示形式。Symbol ValueI 1V 5X 10L 50C 100D 500M 1000 Input: 1994Output: "MCMXCIV"Explanation: M = 1000, CM = 900, XC = 90 and IV
阅读全文
摘要:给定一个数组,数组中的数字在坐标系中按柱状图分布,选取两根柱子,与横坐标形成水池,求最大的水池面积。 Input: [1,8,6,2,5,4,8,3,7]Output: 49 思路:一开始运用暴力结题,O( n*n )的时间复杂度,然而不AC。看了答案,运用两个下标 left = 0, right
阅读全文
摘要:给定一个字符串,将里面的数字提取出来。要注意空格、符号、int 数据越界、前导0。Input: "4193 with words"Output: 4193Explanation: Conversion stops at digit '3' as the next character is not a
阅读全文
摘要:给定一个之字形排列的字符串,给定排成numRows行,要求按行输出。 Input: s = "PAYPALISHIRING", numRows = 4Output: "PINALSIGYAHRPI" 思路: 黑色的数字,每一列都是相差 6。而红色的数字,与它前面的黑色数字,存在如下关系。 规律:这题
阅读全文
摘要:给定一个字符串,求字符串中最长的回文子串。Input: "babad"Output: "bab"Note: "aba" is also a valid answer. 思路:一、暴力解决,O(n^3) 的时间复杂度,最外层循环为 子串的起始位置,第二层循环为,对字符串中的字符遍历,若与子串的第一个字
阅读全文
摘要:给定一个字符串,求出其中最大的子串长度,子串中要求所有字符只出现一次。Input: "abcabcbb"Output: 3 Explanation: The answer is "abc", with the length of 3. 思路:运用2个下标,一个遍历字符串,一个记录子串的起始位置,每次
阅读全文
摘要:给定2个链表,每个链表所代表的数字是反着排列的,比如整数:123,在链表中是 3->2->1,让你求这两个数之和,并也将其和反着排列。Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)Output: 7 -> 0 -> 8Explanation: 342 + 465 = 807
阅读全文
摘要:给定两个等长的字符串,求这两个字符串中相同位置字符相等的个数bull,和不同位置但字符相同的个数cows,最后结合为 bull+A+cows+B.Input: secret = "1807", guess = "7810" Output: "1A3B" Explanation: 1 bull and
阅读全文
摘要:给定一个二叉树,返回所有根节点到叶子节点的路径。Input: 1 / \2 3 \ 5Output: ["1->2->5", "1->3"]Explanation: All root-to-leaf paths are: 1->2->5, 1->3 难点:返回的是vector<string>的容器类
阅读全文
摘要:给定一个模板,和一个字符串,判断字符串中的单词是否如模板那样排列。Input: pattern = "abba", str = "dog cat cat dog"Output: true 难点:这是双射的,需要考虑 pattern -> str;也需要考虑 str -> pattern ,这样才是
阅读全文
摘要:给定一个数组,将数组中的0全部移到数组的末尾,同时保持非0元素的相对顺序不变。Input: [0,1,0,3,12]Output: [1,3,12,0,0] 思路:题目要求不要用到复制数组,所以只能使用交换的方法,且要尽可能少的操作总数。运用2个下标 i, j ,下标 i 记录遍历数组的下标,当遍历
阅读全文
摘要:有一系列产品的版本,如果其中一个版本错了,则在它之后的都错了。调用API函数 isBadVersion( )找到错误开始的源头,要求尽量少的调用API。Given n = 5, and version = 4 is the first bad version. call isBadVersion(3
阅读全文
摘要:给定一个数组,包含0,1,2…….n 的 n个数,输出缺失的那一个。Input: [9,6,4,2,3,5,7,0,1]Output: 8 思路:因为 0 ~ n 共有 n+1个数,而给定的数组中只有 n 个数,n 取决于数组的长度;所以,不管如何,都缺失一个数,偏一点的例子,如: [0,1],则缺
阅读全文
摘要:给定一个数,判断其质因数是否是2,3,5。Input: 6Output: trueExplanation: 6 = 2 × 3 Input: 14Output: false Explanation: 14 is not ugly since it includes another prime fac
阅读全文
摘要:给定一个整数,求每个数位上的数字之和,若结果大于10,则继续相加,直到其结果小于10.Input: 38Output: 2 Explanation: The process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one digit, ret
阅读全文
摘要:Given two strings s and t , write a function to determine if t is an anagram of s.Input: s = "anagram", t = "nagaram"Output: true 难点:没读懂题意,开始以为是映射,提交好
阅读全文
摘要:给定一个单链表中的节点,将这个节点删除。Input: head = [4,5,1,9], node = 5Output: [4,1,9]Explanation: You are given the second node with value 5, the linked list should be
阅读全文
摘要:给定一个二叉搜索树,以及2个节点p, q ,求这两个节点的最近公共祖先。 Input: root = [6,2,8,0,4,7,9,null,null,3,5], p = 2, q = 8Output: 6Explanation: The LCA of nodes 2 and 8 is 6. Inp
阅读全文
摘要:给定一个单链表,求其是否可回读,即,正着读和倒着读一样。Input: 1->2->2->1Output: true 思路:一、遍历链表,将其节点的值存入动态数组中,最后对数组头尾的值遍历判别。 bool isPalindrome(ListNode* head) { vector<int> tmp;
阅读全文
摘要:用栈实现队列的功能。MyQueue queue = new MyQueue(); queue.push(1);queue.push(2); queue.peek(); // returns 1queue.pop(); // returns 1queue.empty(); // returns fal
阅读全文
摘要:判断一个数是否是2为底的幂次函数。Input: 16Output: trueExplanation: 24 = 16 思路:除余法。难点:0和负数别忘了。 bool isPowerOfTwo(int n) { if (n <= 0)return false; while (n > 1) { if (
阅读全文
摘要:给定一个二叉树,将其左右翻转。Input: 4 / \ 2 7 / \ / \1 3 6 9 Output: 4 / \ 7 2 / \ / \9 6 3 1 思路:递归调用,写好出口就行了。如果是叶子节点,则直接将其返回,空节点也直接返回;对于非叶子节点的,将其 root->left = inve
阅读全文
摘要:用队列实现栈的功能。MyStack stack = new MyStack(); stack.push(1);stack.push(2); stack.top(); // returns 2stack.pop(); // returns 2stack.empty(); // returns fals
阅读全文
摘要:给定一个数组,以及一个整数k,判断数组中,是否存在相同的2个数,且这两个数的距离不超过k。Input: nums = [1,2,3,1], k = 3Output: true Input: nums = [1,2,3,1,2,3], k = 2Output: false 思路:一:暴力搜索,提交OJ
阅读全文
摘要:给定一个数组,求其中是否存在重复的元素,有重复,返回true;否则,返回fasle。Input: [1,2,3,1]Output: true 思路:一、用哈希字典存储元素,遍历数组中的元素若存在,则返回false;提交OJ,虽然AC了,但有点慢。 bool containDuplicate(vect
阅读全文
摘要:给定两个字符串,判断其是否是同构的。何为同构,即字符串中每个字符都是单一映射的。Input: s = "egg", t = "add"Output: true Input: s = "foo", t = "bar"Output: false 思路:设置两个哈希字典,一个保存s到t的映射,另一个保存t
阅读全文
摘要:给定一个正整数,求小于这个数的质数个数。Input: 10Output: 4Explanation: There are 4 prime numbers less than 10, they are 2, 3, 5, 7. 思路:一、暴力,利用for循环,对 2~n的数遍历,当遇到质数时,将其加入动
阅读全文
摘要:给定一个链表,要求将其反转:Input: 1->2->3->4->5->NULLOutput: 5->4->3->2->1->NULL 思路:运用2个临时指针,一个表示反转后的链表的头结点 p,一个表示给定链表的当前节点 tmp_p = head,使用 tmp_p -> next = p; p =
阅读全文
摘要:给定一个链表和一个整数,要求删除链表上值为给定整数的节点。Input: 1->2->6->3->4->5->6, val = 6Output: 1->2->3->4->5 思路:对给定链表循环,如果节点上的值等于给定的val,则跳过,否则将其加入到新链表上。难点:当最后一个节点要去除时,由于它值等于
阅读全文
摘要:给定一个数,得到这个数的数位上的数字的平方和,然后循环,如果最后能等于1,则输出true,否则为false. 难点:不知道这个数到底要循环多少轮才能得到1.思路:设置一个最大的循环数(如:20轮),如果达到最大循环次数,还不等于1,则返回false. #include<iostream> #incl
阅读全文
摘要:#include<iostream> #include<vector> #include<algorithm> using namespace std; int rob(vector<int>& nums) { if (nums.size() == 0) return 0; if (nums.siz
阅读全文
摘要:#include<iostream> #include<string> using namespace std; int hammingWeight(uint32_t n) { int ans = 0; while (n) { if (n % 2 == 1) { ans += 1; } n = n
阅读全文
摘要:#include<iostream> #include<string> using namespace std; uint32_t reverseBits(uint32_t n) { uint32_t a = 0; int count = 0; string s = ""; while (n) {
阅读全文
摘要:class Solution: def romanToInt(self, s: str) -> int: dic = {} dic["I"] = 1 dic["V"] = 5 dic["X"] = 10 dic["L"] = 50 dic["C"] = 100 dic["D"] = 500 dic[
阅读全文
摘要:class Solution: def longestCommonPrefix(self, strs: List[str]) -> str: if len(strs) == 0: return "" last_s = strs[0] same_prefix = "" for i, s in enum
阅读全文
摘要:class Solution: def isValid(self, s: str) -> bool: dic = {"(":")",")":"(","[":"]","]":"[","{":"}","}":"{"} if len(s) == 0: return True else: stack = "
阅读全文
摘要:class Solution: def removeDuplicates(self, nums: List[int]) -> int: j = 0 for i in range(len(nums)): if i >j and nums[i] > nums[j] : j += 1 nums[j] =
阅读全文
摘要:# Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: def mergeTwoLists(se
阅读全文
摘要:class Solution: def removeElement(self, nums: List[int], val: int) -> int: j = 0 for i, v in enumerate(nums): if v != val: nums[j] = v j += 1 return j
阅读全文
摘要:class Solution: def strStr(self, haystack: str, needle: str) -> int: if len(needle) == 0: return 0 else: for i in range(len(haystack)): if haystack[i:
阅读全文
摘要:class Solution: def searchInsert(self, nums: List[int], target: int) -> int: if len(nums) == 0: return 0 else: for i in range(len(nums)): if nums[i] >
阅读全文
摘要:class Solution: def countAndSay(self, n: int) -> str: if n == 1 : return "1" if n == 2: return "11" s = "11" for i in range(2,n): tmp_s = "" count = 1
阅读全文
摘要:class Solution: def lengthOfLastWord(self, s: str) -> int: if len(s) == 0: return 0 s = s[::-1] length = 0 for i,v in enumerate(s): if v == " ": if le
阅读全文
摘要:class Solution: def maxSubArray(self, nums: List[int]) -> int: n = len(nums) res = float('-inf') tmp = 0 for i in range(n): if tmp < 0: tmp = 0 tmp =
阅读全文
摘要:class Solution: def plusOne(self, digits: List[int]) -> List[int]: n = len(digits) s = "" for i in range(n): s += str(digits[i]) s = int(s) + 1 s = st
阅读全文
摘要:class Solution: def addBinary(self, a: str, b: str) -> str: n = len(a) if len(a) > len(b) else len(b) a = a[::-1] b = b[::-1] tmp = 0 ans = "" for i i
阅读全文
摘要:class Solution: def climbStairs(self, n: int) -> int: dp = [1 for i in range(n+1)] for i in range(2, n+1): dp[i] = dp[i-1] + dp[i-2] return dp[n]
阅读全文
摘要:# Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: def deleteDuplicates
阅读全文
摘要:class Solution: def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> None: """ Do not return anything, modify nums1 in-place instead
阅读全文
摘要:# Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution:
阅读全文
摘要:# Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None, right=None): # self.val = val # self.left = left # self.
阅读全文
摘要:class Solution: def generate(self, numRows: int) -> List[List[int]]: if numRows == 0: return None if numRows == 1: return [[1]] ans = [[1]] for j in r
阅读全文
摘要:class Solution: def maxProfit(self, prices: List[int]) -> int: length = len(prices) if length == 0: return 0 minBuyPrice = prices[0] maxProfit = 0 for
阅读全文
摘要:class Solution: def singleNumber(self, nums: List[int]) -> int: a = 0 for i in range(len(nums)): a = a^nums[i] return a
阅读全文
摘要:class MinStack: def __init__(self): """ initialize your data structure here. """ self.stack = [] def push(self, x: int) -> None: if len(self.stack) ==
阅读全文
摘要:class Solution: def twoSum(self, numbers: List[int], target: int) -> List[int]: lp = 0 rp = len(numbers) - 1 while lp < rp: if numbers[lp] + numbers[r
阅读全文
摘要:class Solution: def majorityElement(self, nums: List[int]) -> int: if len(nums) == 1: return nums[0] dic = {} n = len(nums) // 2 for i in range(len(nu
阅读全文
摘要:class Solution: def titleToNumber(self, s: str) -> int: ans = 0 for i in range(len(s)): ans = ans * 26 + ord(s[i])-64 return ans
阅读全文
摘要:class Solution: def rotate(self, nums: List[int], k: int) -> None: """ Do not return anything, modify nums in-place instead. """ lenList = len(nums) w
阅读全文
摘要:class Solution: def trailingZeroes(self, n: int) -> int: if n < 5: return 0 return n//5 + self.trailingZeroes(n//5)
阅读全文
摘要:class Solution: def convertToTitle(self, n: int) -> str: ans = "" while n: a = (n-1) % 26 n = (n-1) // 26 ans = chr(ord('A') + a) + ans return ans
阅读全文
摘要:# Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: def getIntersectionN
阅读全文
摘要:# Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: def hasCycle(self, h
阅读全文
摘要:class Solution: def isPalindrome(self, s: str) -> bool: s1 = s.split() s_tmp = "" for i in range(len(s1)): for j in range(len(s1[i])): if 'a'<= s1[i][
阅读全文
摘要:class Solution: def maxProfit(self, prices: List[int]) -> int: length = len(prices) if length == 0: return 0 maxProfit = 0 minBuyPrice = prices[0] for
阅读全文
摘要:class Solution: def getRow(self, rowIndex: int) -> List[int]: ans = [1] for i in range(rowIndex + 1): tmp = [1 for i in range(i + 1)] for j in range(1
阅读全文
摘要:# Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None, right=None): # self.val = val # self.left = left # self.
阅读全文
摘要:# Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None, right=None): # self.val = val # self.left = left # self.
阅读全文
摘要:# Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution:
阅读全文
摘要:# Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution:
阅读全文
摘要:# Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution:
阅读全文
摘要:# Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution:
阅读全文
摘要:class Solution: def isPalindrome(self, x: int) -> bool: if x < 0: return False else: x_copy = x pal_num = 0 while x: pal_num = pal_num *10 + x % 10 x
阅读全文
摘要:class Solution: def reverse(self, x: int) -> int: isNegative = x < 0 sum = 0 abs_x = abs(x) while abs_x: sum = sum * 10 i = abs_x % 10 sum = sum + i a
阅读全文
摘要:class Solution: def twoSum(self, nums, target): """ :param nums: List[int] :param target:int :return:Lsit[int] """ reverse = {} for i , v in enumerate
阅读全文