自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(68)
  • 收藏
  • 关注

转载 Trie树|字典树(字符串排序)

有时,我们会碰到对字符串的排序,若采用一些经典的排序算法,则时间复杂度一般为O(n*lgn),但若采用Trie树,则时间复杂度仅为O(n)。Trie树又名字典树,从字面意思即可理解,这种树的结构像英文字典一样,相邻的单词一般前缀相同,之所以时间复杂度低,是因为其采用了以空间换取时间的策略。下图为一个针对字符串排序的Trie树(我们假设在这里字符串都是小写字母),每个结点有26个分支

2015-11-11 16:14:12 436

转载 常用海量数据处理方法

1.Bloom filter 适用范围:可以用来实现数据字典,进行数据的判重,或者集合求交集 基本原理及要点: 对于原理来说很简单,位数组+k个独立hash函数。将hash函数对应的值的位数组置1,查找时如果发现所有hash函数对应位都是1说明存在,很明显这个过程并不保证查找的结果是100%正确的。同时也不支持删除一个已经插入的关键字,因为该关键字对应的位会牵动到其他的关键字。

2015-11-11 16:04:37 328

转载 负载平衡

负载平衡负载均衡是由多台服务器以对称的方式组成一个服务器集合,每台服务器都具有等价的地位,都可以单独对外提供服务而无须其他服务器的辅助。通过某种负载分担技术,将外部发送来的请求均匀分配到对称结构中的某一台服务器上,而接收到请求的服务器独立地回应客户的请求。均衡负载能够平均分配客户请求到服务器列阵,籍此提供快速获取重要数据,解决大量并发访问服务问题。这种群集技术可以用最少的投资获得接近于大型主机的

2015-11-11 16:01:10 470

原创 leetcode-Implement Queue using Stacks

Difficulty: EasyImplement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue.pop() -- Removes the element from in front of queue.peek() -- Get th

2015-11-11 12:35:51 280

原创 leetcode-Kth Largest Element in an Array

Difficulty: MediumFind the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.For example,Given [3,2,1,5,6,4] a

2015-11-11 12:09:59 302

原创 leetcode-Isomorphic Strings

Difficulty: Easy Given two strings s and t, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to gett.All occurrences of a character must be re

2015-11-11 11:27:38 275

原创 leetcode-Triangle

Difficulty: Medium Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [

2015-11-10 23:34:42 293

原创 leetcode-Reorder List

Difficulty: MediumGiven a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For example,Given {1,2,

2015-11-10 20:33:42 267

原创 leetcode-Reverse Integer

Difficulty: EasyReverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321class Solution { public: int reverse(int x) {

2015-11-10 20:13:57 287

原创 leetcode-Symmetric Tree

Difficulty: Easy Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \3 4 4 3

2015-11-10 20:00:17 294

原创 leetcode-Balanced Binary Tree

Difficulty: EasyGiven a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees ofeve

2015-11-10 19:43:48 266

原创 leetcode-Lowest Common Ancestor of a Binary Search Tree

Difficulty: Easy Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia: “The lowest common ancesto

2015-11-09 23:36:49 222

原创 leetcode-Search for a Range

Difficulty: Medium 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(logn).If the ta

2015-11-09 23:08:44 266

原创 leetcode-Unique Paths II

Difficulty: MediumFollow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as 1 and 0 resp

2015-11-09 22:53:07 264

原创 leetcode-Unique Paths

Difficulty: MediumA robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is

2015-11-09 22:40:02 280

原创 leetcode-Minimum Path Sum

Difficulty: MediumGiven a m x n grid filled with non-negative numbers, find a path from top left to bottom right whichminimizes the sum of all numbers along its path.Note: You can only move ei

2015-11-09 22:32:21 393

原创 leetcode-Binary Tree Maximum Path Sum

Difficulty: HardGiven a binary tree, find the maximum path sum.For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child

2015-11-09 22:16:10 284

原创 leetcode-Sum Root to Leaf Numbers

Difficulty: MediumGiven a binary tree containing digits from0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path1->2->3 which represents the number

2015-11-09 21:55:31 502

原创 leetcode-Linked List Cycle II

Difficulty: MediumGiven a linked list, return the node where the cycle begins. If there is no cycle, returnnull.Note: Do not modify the linked list.Follow up:Can you solve it without using

2015-11-09 11:49:00 293

原创 leetcode-Linked List Cycle

Difficulty: MediumGiven 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. * struct ListNode {

2015-11-09 11:37:54 288

原创 leetcode-Remove Linked List Elements

Difficulty: EasyRemove all elements from a linked list of integers that have valueval.ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --> 2 --> 3 --> 4 --> 5/** *

2015-11-07 22:40:54 282

原创 leetcode-Remove Duplicates from Sorted List

Difficulty: EasyGiven a sorted linked list, delete all duplicates such that each element appear onlyonce.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3./** *

2015-11-07 22:21:36 278

原创 leetcode-Remove Duplicates from Sorted List II

Difficulty: MediumGiven a sorted linked list, delete all nodes that have duplicate numbers, leaving onlydistinct numbers from the original list.For example,Given 1->2->3->3->4->4->5, r

2015-11-07 22:02:37 327

原创 leetcode-Permutations

Difficulty: MediumGiven a collection of numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1],[3,1,2], and [3,2,1

2015-11-07 20:48:02 262

原创 leetcode-Combinations

Difficulty: MediumGiven two integers n and k, return all possible combinations ofk numbers out of 1 ... n.If n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1,3], [

2015-11-07 20:27:09 291

转载 lintcode- 乘积最大子序列

找出一个序列中乘积最大的连续子序列(至少包含一个数)。您在真实的面试中是否遇到过这个题?样例 比如, 序列 [2,3,-2,4] 中乘积最大的子序列为 [2,3] ,其乘积为6 class Solution { public: int maxProduct(vector& nums) {

2015-11-06 23:25:41 429

原创 leetcode-Path Sum II

Difficulty:MediumGiven 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 and sum = 22, 5

2015-11-06 23:05:24 317

原创 leetcode-Binary Tree Paths

Difficulty:Easy Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths are:["1->2->5", "1->3"]/

2015-11-06 22:46:16 288

原创 leetcode-Reverse Bits

Difficulty: EasyReverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in bin

2015-11-06 22:15:32 281

原创 leetcode-3Sum Closest

Difficulty:Medium Given an array S of n integers, find three integers inS such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each

2015-11-06 22:10:10 254

原创 leetcode-First Missing Positive

Difficulty:Hard 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

2015-11-06 21:16:12 221

原创 leetcode-Remove Duplicates from Sorted Array

Difficulty:Easy Given a sorted array, remove the duplicates in place such that each element appear onlyonce and return the new length.Do not allocate extra space for another array, you

2015-11-06 20:43:08 241

原创 leetcode-Majority Element

Difficulty:Easy Given an array of size n, find the majority element. The majority element is the element that appears more than⌊ n/2 ⌋ times.You may assume that the array is non-empty and th

2015-11-06 20:32:07 217

原创 leetcode-Summary Ranges

Difficulty: Easy Given a sorted integer array without duplicates, return the summary of its ranges.For example, given [0,1,2,4,5,7], return["0->2","4->5","7"].class Solution {public: ve

2015-11-06 20:23:23 309

原创 leetcode-Pascal's Triangle

Difficulty:Easy Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]class S

2015-11-06 19:41:52 269

原创 leetcode-Pascal's Triangle II

Difficulty:Easy Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].Note:Could you optimize your algorithm to use only O(k) extra space?

2015-11-06 19:30:22 350

原创 leetocde-Maximum Depth of Binary Tree

Difficulty:Easy 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.class Solution {p

2015-11-06 00:13:04 276

原创 leetcode-Minimum Depth of Binary Tree

Difficulty: EasyGiven a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node./** * Definition fo

2015-11-06 00:08:58 281

原创 leetcode-Path Sum

Total Accepted: 76998 Total Submissions: 255687 Difficulty: Easy 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 eq

2015-11-06 00:00:45 361

原创 leetcode-Valid Anagram

Difficulty: Easy Given two strings s and t, write a function to determine ift is an anagram of s.For example,s = "anagram", t = "nagaram", return true.s = "rat", t = "car", return false.

2015-11-05 23:24:14 302

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除