【067-Add Binary(二进制加法)】【LeetCode-面试算法经典-Java实现】【所有题目目录索引】原题 Given two binary strings, return their sum (also a binary string).
For example,
a = "11"
b = "1"
Return "100"
题目大意 给定两个二进制的字符串...
分类:
编程语言 时间:
2015-08-02 06:23:42
阅读次数:
194
4.4 Given a binary tree, design an algorithm which creates a linked list of all the nodes at each depth (e.g., if you have a tree with depth D, you'll...
分类:
其他好文 时间:
2015-08-02 00:55:41
阅读次数:
137
Reverse Bits
Reverse bits of a given 32 bits unsigned integer.
For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represen...
分类:
其他好文 时间:
2015-08-01 23:36:18
阅读次数:
145
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree andsum =...
分类:
其他好文 时间:
2015-08-01 23:27:33
阅读次数:
114
Given inorder and postorder traversal of a tree, construct the binary tree.
Note:
You may assume that duplicates do not exist in the tree.
思路:这题和上题类似,前序第一个是根节点,后序遍历最后一个是根节点。其余步骤类似。
代码如下:
/**
*...
分类:
其他好文 时间:
2015-08-01 22:10:16
阅读次数:
150
Given preorder and inorder traversal of a tree, construct the binary tree.
Note:
You may assume that duplicates do not exist in the tree.
思路:首先根据前序遍历得到根节点,然后在中序遍历中得到根节点的位置,左边的为左子树,右边的为右子树。
然后再...
分类:
其他好文 时间:
2015-08-01 22:09:32
阅读次数:
138
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).
For example:
Given binary ...
分类:
其他好文 时间:
2015-08-01 22:08:36
阅读次数:
141
Given a binary tree, find its maximum depth.
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
思路:很基础的一个题,DFS即可。代码如下:
/**
* Defin...
分类:
其他好文 时间:
2015-08-01 22:08:25
阅读次数:
140
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).
For example:
Given binary tree {3,9,20,#,#,15,7},
...
分类:
其他好文 时间:
2015-08-01 22:07:00
阅读次数:
129
Question
Implement int sqrt(int x).
Compute and return the square root of x.
My Solution
class Solution {
public:
int mySqrt(int x) {
/**
* binary search a from [0, x], where a^2 = x....
分类:
其他好文 时间:
2015-08-01 22:06:03
阅读次数:
87