Given two binary strings, return their sum (also a binary string).
For example,
a = "11"
b = "1"
Return "100".
具体一位一位地加就行了,考虑进位的问题。还有最后记得把生成的string反过来再返回,因为我们是从最低位开始加的。
public class Solu...
分类:
其他好文 时间:
2014-08-30 01:16:58
阅读次数:
286
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.
For example:
Given the below binary tree and sum
...
分类:
其他好文 时间:
2014-08-29 22:42:32
阅读次数:
328
题意:
给你半个矩阵 如果(i,j)的位置是'-' 则说明sum[i...j]0 如果是'0' 说明sum=0 给出一种满足这个矩阵的序列 序列元素绝对值在10以内
思路:
很容易想到的是将sum[i...j]转化为sum[j]-sum[i-1] 即用前缀和来表示 那么题中的矩阵就可以转化成前缀和之间的大小比较 也就是说 我们可以通过将前缀和当成点 将大小关系作为边...
分类:
其他好文 时间:
2014-08-29 20:07:28
阅读次数:
236
# Definition for a binary tree nodeclass TreeNode: def __init__(self, x): self.val = x self.left = None self.right = Noneclas...
分类:
其他好文 时间:
2014-08-29 17:36:18
阅读次数:
135
常常写SQL语句的人应该知道Group by语句的主要使用方法是进行分类汇总,以下是一种它最常见的使用方法(依据部门、职位分别统计业绩):SELECT a.dname,b.job,SUM(b.sal) sum_salFROM dept a,emp bWHERE a.deptno = b.deptn....
分类:
数据库 时间:
2014-08-29 17:31:18
阅读次数:
344
秩$1$矩阵$\bf命题:$设实矩阵$A = {\left( {{a_1}, \cdots ,{a_n}} \right)^T}\left( {{a_1}, \cdots ,{a_n}} \right)$,且$\sum\limits_{k = 1}^n {{a_k}^2} = 1$,证明:$\lef...
分类:
其他好文 时间:
2014-08-29 10:51:27
阅读次数:
235
这个专题充分暴露了不认真思考的缺点,总是感觉差不多就下手。
对于A题目,以为是强连通分量缩点。但实际上是求桥。
并考虑:1.重边 2.权重为0则初始值不能赋值为0,当选取权重为0的边答案为1 3.没有答案。
对于B题目,起初想得很复杂,以为是动态规划,一直在思考转移方程。但其实DFS就可以,但漏掉了形成正方形的另一个条件,底边平行。
对于C题目,这里又出现了漏洞(直接DFS不用考虑这些)...
分类:
其他好文 时间:
2014-08-29 09:29:27
阅读次数:
220
Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array[?2,1,?3,4,?1,2,1,...
分类:
其他好文 时间:
2014-08-29 01:18:46
阅读次数:
187
给定一个整数数组(长度不小于3) 和 一个目标值, 从数组中找出3个元素, 使得它们的和与目标值最接近, 返回这个和. 可以认为每个输入的组合都是只有唯一解的.解法思路参考: Finding three elements in an array whose sum is closest to an ...
分类:
其他好文 时间:
2014-08-28 22:38:06
阅读次数:
212
Problem code: LCMSUMGiven n, calculate the sum LCM(1,n) + LCM(2,n) + .. + LCM(n,n), where LCM(i,n) denotes the Least Common Multiple of the integers i...
分类:
其他好文 时间:
2014-08-28 22:23:56
阅读次数:
347