### LeetCode

leetcode题解

0 已关注
17篇博文
• #### 弗洛伊德判圈算法

先来看链表是否有环的判断 设链表起始节点为H，回路起始节点为S，两指针第一次相遇节点为M。 设回路的长度为c，S到M的距离为c1，M到S的距离为c2。 设H到S的距离为d。 设hare每次移动2，to...

2015-10-08 21:29
1404
• #### 二分搜索

Sqrt(x)   Implement int sqrt(int x). Compute and return the square root of x.

2015-04-01 18:20
360
• #### LRU cache

实现lru 缓存 LRU Cache  Total Accepted: 35641 Total Submissions: 241374My Submissions Question  S...

2015-04-09 15:28
737
• #### 层次遍历二叉树

public class Solution { static class Queue { static final int MAX_SIZE = 1 << 10; ...

2015-04-10 17:29
508
• #### 复制无向带环图

Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors. ...

2015-04-13 16:06
709
• #### BST迭代器

Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the ro...

2015-04-16 16:19
750
• #### 先序和中序建立二叉树

Construct Binary Tree from Preorder and Inorder Traversal   Given preorder and inorder trave...

2015-04-23 12:50
1091
• #### 变位分词

static int prime[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73...

2015-04-24 22:44
564
• #### 判断二叉树是否对称

static boolean isMirror(TreeNode left, TreeNode right) { if (left == null && right == null) ...

2015-04-24 21:42
1055
• #### 求二叉树最远距离

int max=Integer.MIN_VALUE; int maxHeightSum(TreeNode root) { if (root == null) return 0...

2015-04-25 19:14
484
• #### 文件路径化简

Given an absolute path for a file (Unix-style), simplify it. For example, path = "/home/", => "/...

2015-04-29 16:37
511
• #### 平衡二叉树判定

1. int height(TreeNode root) { if (root == null) return 0; return Math.max(height(ro...

2015-04-29 18:44
435
• #### 将升序数组转化为平衡二叉树

public class Solution { TreeNode convert(int num[], int l, int r) { if (l >= r) return n...

2015-04-29 20:13
985
• #### Best Time to Buy and Sell Stock IV

Say you have an array for which the ith element is the price of a given stock on day i. Design an a...

2015-05-03 14:43
784
• #### N皇后问题

The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens ...

2015-05-10 12:57
445
• #### 用dfs实现拓扑排序

拓扑排序，详见算法导论 There are a total of n courses you have to take, labeled from 0 to n - 1. Some cours...

2015-05-16 00:27
590
• #### 有向图判断是否有环

There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have...

2015-05-13 23:41
503