1 题目 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 -…
Palindrome Number Total Accepted: 19369 Total Submissions: 66673My Submissions Determine whether an integer is a palindrome. Do this without extra space. 推断一个数整数是不是回文?比如121,1221就是回文,好吧,直接利用前面写过的[Leet Code]Reverse Integer--"%"你真的懂吗? 只是这里要考虑翻转后,数值…
很简单一道题,搞错了N次,记录一下. public class Solution { private int currSum = 0; public boolean hasPathSum(TreeNode root, int sum) { if (null == root) return false; currSum = 0; return hasPathSumCore(root, sum); } public boolean hasPathSumCore(TreeNode root, int…
描述:不使用 * / % 完成除法操作.O(n)复杂度会超时,需要O(lg(n))复杂度. 代码: class Solution: # @return an integer def dividePositive(self, dividend, divisor): if dividend < divisor: return 0 sum = divisor count = 1 while sum + sum < dividend: sum += sum count += count count +…
语言:Python 描述:使用递归实现 def getList(self, node): if node is None: return [] if node.left is None and node.right is None: return [[node.val]] result = [] for item in self.getList(node.left): result.append([node.val] + item) for item in self.getList(node.r…
1 题目 There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). 2 思路 这题比较简单,实现的其实就是归并排序merge那个部分. 3 代码 public class MedianOfTwoSortedArrays { pub…