- 博客(101)
- 资源 (7)
- 收藏
- 关注
原创 Split array into two equal sum subArray
@(leetcode)[数组|Google]ProblemA zero-indexed array A consisting of N integers is given. An equilibrium index of this array is any integer P such that 0 ≤ P < N and the sum of elements of lower indices i
2016-08-26 18:02:38 1409
原创 Line reconstruction by height
ProblemSuppose you have a line of n people in which the k-th person is described by a pair (h,t) , where h is the height of the k-th person and t is the number of people in front of k who have a height
2016-08-23 16:03:13 651
原创 Find number of subsets with equal sum
@(leetcode)[动态规划|Google]ProblemGiven a number N ( N > 1), gives a set S = [1,2,..., N]. Divide S in two subsets such that S1 ∪ S2 = S and S1 ∩ S2 = Ø and return the number of subsets with equal sum.Ex
2016-08-23 13:26:47 521
原创 The longest absolute path in file system
The longest absolute path in file system@(leetcode)[字符串|DFS|Google] The string "dir\n\tsubdir1\n\tsubdir2\n\t\tfile.ext" represents:dir subdir1 subdir2 file.exta directory dir contains an
2016-08-23 13:07:48 585
原创 Shortest substring containing three short strings
@(leetcode)[字符串, Google]ProblemGiven a long string s and short strings t1, t2, t3 (which can have different length) find the shortest substring of s which contains t1, t2 and t3.Example: s = "abcdefgh
2016-08-22 16:55:10 507
原创 Maximum traffic between city and its neighbors
@(leetcode)[图论|Google]ProblemYou are given a graph with no cycles, each node representing different cities and there are stadiums for baseball games in all cities. Each node contains a value representi
2016-08-22 16:54:17 636
原创 386. Lexicographical Numbers
ProblemGiven an integer n, return 1 - n in lexicographical order.For example, given 13, return:[1,10,11,12,13,2,3,4,5,6,7,8,9].Please optimize your algorithm to use less time and space. The input size
2016-08-21 16:28:49 1417
原创 384. Shuffle an Array
@(leetcode)[数组]ProblemShuffle a set of numbers without duplicates.Example: // Init an array with set 1, 2, and 3. int[] nums = {1,2,3}; Solution solution = new Solution(nums); // Shuffle the
2016-08-21 16:02:53 375
原创 38. Count and Say
ProblemThe count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221, ...1is read off as "one 1" or 11 11is read off as"two 1s"or21 21is read off as"one 2then
2016-08-21 16:01:57 315
原创 37. Sudoku Solver
ProblemWrite a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character .You may assume that there will be only one unique solution. A sudoku puzzle…Solut
2016-08-21 16:01:08 329
原创 59. Spiral Matrix II
ProblemGiven an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.For example, Given n = 3,You should return the following matrix: [ [ 1, 2, 3 ], [ 8, 9,
2016-08-21 15:59:54 275
原创 Word Ladder II
Given two words (beginWord and endWord), and a dictionary’s word list, find all shortest transformation sequence(s) from beginWord to endWord, such that:Only one letter can be changed at a time Each i
2016-08-21 15:58:47 369
原创 133. Clone Graph
# @(leetcode)[BFS, 图论]Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.OJ’s undirected graph serialization: Nodes are labeled uniquely.We use # as a sepa
2016-08-21 15:55:35 305
原创 Unique Binary Search Trees II
Unique Binary Search Trees II@(leetcode)[枚举, DFS]Given an integer n, generate all structurally unique BST’s (binary search trees) that store values 1…n.For example, Given n = 3, your program should re
2016-08-21 15:54:36 931
原创 65. Valid Number
65. Valid NumberProblemValidate if a given string is numeric.Some examples: "0" => true " 0.1 " => true "abc" => false "1 a" => false "2e10" => trueNote: It is intended for the problem statement t
2016-08-21 15:52:49 365
原创 Redis数据库实现
Redis服务器将所有数据库都保存在服务器状态redis.h/redisServer结构的db数组中,db数组的每一项都是一个redisDb结构,每个redisDb代表一个数据库。struct redisServer { redisDb *db; int dbnum;//该值是由服务器配置的database选项决定,默认值是16};
2016-07-08 17:36:26 394
原创 Redis 对象
Redis并没有直接使用这些基础数据结构实现键值对的数据库,而是基于这些数据结构创建一个对象系统。包括字符串对象,列表对象,哈希对象,集合对象和有序集合对象。 Redis中每个对象都由一个redisObject结构表示,该结构如下:typedef struct redisObject { unsigned type:4;//类型,记录了对象的类型, 这个类型
2016-06-22 09:55:23 425
原创 Redis 数据结构
Redis 数据结构最近接触到了Redis的使用,借这个机会深入的了解一下Redis的实现和设计原理。下面先介绍一下Redis底层所用到的数据结构。Redis的实现几乎都是基于下面的几个数据结构之上的。1.SDS 结构struct sdshdr { int len; // 记录数组中已经使用的字节数量,不算结尾的\0 int free;
2016-06-21 22:48:56 350
原创 算法乐趣--三只水桶等分水问题
有一个容积为8升的水桶里装满了水,另外还有一个容积为3升的空桶和一个容积为5升的空桶,如何利用这两个空桶等分8升水?附加条件是三个水桶都没有体积刻度,也不能使用其它辅助容器。 这是一道经典题目,一般人都可以在一分钟内给出答案,不过,很多人可能没有注意到这道题的答案不是唯一的。先来看看最常见的一个答案,也是目前已知最快的操作步骤,共需要7次倒水动作:bucket_sta
2016-01-22 17:19:01 9841
原创 二叉树的最小深度
1,题目要求,求一个二叉树的最小深度?int minHeight(TreeNode* root) { if(NULL == root) return 0; int left = minHeight(root->left); int right minHeight(root->right); if(left == 0 && right == 0)
2016-01-11 23:19:55 338
原创 LeetCode Flatten Binary Tree to Linked List
Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look like: 1
2014-08-11 22:02:59 659
原创 Leetcode Trapping Rain Water
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example, Given [0,1,0,2,1,0,1,3,2,1,2,1]
2014-08-10 16:12:04 431
原创 Leetcode(Search in Rotated Sorted Array II )
Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Write a function to determine if a given target is in the
2014-08-09 21:36:39 467
原创 Leetcode (Generate Parentheses )
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:"((()))", "(()())", "(())()", "()(())", "()()
2014-08-09 17:18:50 468
原创 Leetcode(Sort Colors )
Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the integers
2014-08-09 16:44:37 571
原创 LeetCode Search for a Range
题目要求:Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the target is
2014-05-14 03:43:41 469
原创 LeetCode First Missing Positive
题目要求:Given an unsorted integer array, find the first missing positive integer.For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Your algorithm should run in O(n) time and us
2014-05-13 23:02:49 523
原创 LeetCode Best Time to Buy and Sell Stock III
题目要求:Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most two transactions.Note
2014-05-13 04:43:58 705
原创 LeetCode Multiply Strings 大数相乘
题目要求:Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-negative.daima
2014-05-13 02:14:37 849
原创 LeetCode(Longest Consecutive Sequence ) 最长连续序列
题目要求:Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given [100, 4, 200, 1, 3, 2],The longest consecutive elements sequence
2014-05-12 23:40:58 660
原创 LeetCode(Search in Rotated Sorted Array)
题目要求:Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to search. If found in the
2014-04-25 05:15:37 524
原创 LeetCode(Subsets)找出一个集合的所有子集
题目要求:Given a set of distinct integers, S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.
2014-04-25 03:17:32 2470
原创 LeetCode(Validate Binary Search Tree) 判断一个二叉树是否是二叉搜索树
题目要求: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 no
2014-04-25 02:32:58 934
原创 LeetCode(Binary Tree Maximum Path Sum) 在二叉树中找出一条和最大的路径
题目要求:Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary tree, 1 / \ 2 3R
2014-04-25 01:56:25 929
原创 LeetCode(Sum Root to Leaf Numbers)
题目要求:Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number 123.
2014-04-23 10:40:06 558
原创 LeetCode(Palindrome partition 2) 求将一个字符串划分成回文子串 需要分成的段数最少是多少
题目要求:Given a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning of s.For example, given s = "aa
2014-04-23 10:38:34 1519
原创 LeetCode(Minimum Path Sum) 找到路径中和最小的
题目要求:Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down
2014-04-18 04:21:53 700
原创 LeetCode(Word Search)
题目要求:Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or
2014-04-18 01:26:15 520
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人