Dijkstra最短路径算法:dijkstra 算法的优点在于可以求出从一点到所有其他点的最短距离;input:5 71 2 101 3 201 5 302 5 102 3 54 5 204 3 30output:0 10 15 40 20//这是求的在这颗树中,1到所有点的最短距离 1 #incl...
分类:
其他好文 时间:
2014-07-17 22:11:18
阅读次数:
414
Given a binary tree, return the preorder traversal of its nodes' values.
For example:
Given binary tree {1,#,2,3},
1
2
/
3
return [1,2,3].
/**
* Definition for bi...
分类:
其他好文 时间:
2014-07-13 18:46:25
阅读次数:
249
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 link...
分类:
其他好文 时间:
2014-07-13 18:20:52
阅读次数:
202
Given a binary tree, return the postorder traversal of its nodes' values.
For example:
Given binary tree {1,#,2,3},
1
2
/
3
return [3,2,1].
Note: Recursive solut...
分类:
其他好文 时间:
2014-07-13 17:18:19
阅读次数:
193
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).
For example, this binary tree is symmetric:...
分类:
其他好文 时间:
2014-07-13 17:13:49
阅读次数:
213
Given a binary tree, determine if it is a valid binary search tree (BST).
Assume a BST is defined as follows:
The left subtree of a node contains only nodes with keys less than the node's key.Th...
分类:
其他好文 时间:
2014-07-13 16:53:01
阅读次数:
189
Given a linked list, determine if it has a cycle in it.
Follow up:
Can you solve it without using extra space?
/**
* Definition for singly-linked list.
* class ListNode {
* int val;
* ...
分类:
其他好文 时间:
2014-07-13 16:32:04
阅读次数:
152
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-07-13 13:58:01
阅读次数:
184
Evaluate the value of an arithmetic expression in Reverse Polish Notation.
Valid operators are +, -, *, /.
Each operand may be an integer or another expression.
Some examples:
["2", "1", ...
分类:
其他好文 时间:
2014-07-12 22:43:17
阅读次数:
267
Given two binary strings, return their sum (also a binary string).
For example,
a = "11"
b = "1"
Return "100".
public class Solution {
public String addBinary(String a, String b) {
...
分类:
其他好文 时间:
2014-07-12 19:42:26
阅读次数:
168