自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 Dungeon Game

The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a 2D grid. Our valiant knight (K) was initially pos

2015-01-30 22:42:27 592

原创 Find Minimum in Rotated Sorted Array I && II

这些题比较考验边界条件Find Minimum in Rotated Sorted Array class Solution {public: int findMin(vector &num) { int left = 0, right = num.size()-1; while(num[left] > num[right]){

2015-01-30 18:40:38 578

原创 Median of Two Sorted Arrays

There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).用二分的方法求合并数组的中值。用找第k大的值来求,不断去掉较小的一半,

2015-01-29 11:20:45 593

原创 Search a 2D Matrix

Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to right.The first integer of each

2015-01-29 00:36:28 609

原创 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 not found in

2015-01-29 00:22:23 584

原创 Search in Rotated Sorted Array I && II

对翻过一次的排序数组二分查找,要利用好已排序这个条件class Solution {public: int search(int A[], int n, int target) { int left = 0, right = n-1; while(left <= right){ int mid = (left+right)/2

2015-01-28 16:20:02 578

原创 Balanced Binary Tree

检测一个树是否平衡,不需要求出高度,而是从底到顶检测是否平衡,这样才算法时间复杂度为O(n)。但是需要额外的O(logn)的空间/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(

2015-01-27 21:19:31 540

原创 Binary Search Tree Iterator

Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Calling next() will return the next smallest number in the BST.Note: next() and

2015-01-27 21:07:19 561

原创 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.求树的一点到另一点的最大路径,利用递归的方法,ans 在 左子树,右子树,root+左+右的最大中产生。/** * Definition for binary tree * struct

2015-01-27 20:24:19 547

原创 Path Sum II

利用递归处理/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */clas

2015-01-25 00:58:21 949

原创 [leetcode]Largest Number

Given a list of non negative integers, arrange them such that they form the largest number.For example, given [3, 30, 34, 5, 9], the largest formed number is9534330.Note: The result may be very

2015-01-24 14:22:28 593

原创 Unique Binary Search Trees II

生成不相同的二叉树/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */c

2015-01-22 10:49:45 587

原创 二叉树的非递归遍历

先是中序遍历/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */...

2015-01-21 21:37:45 625

原创 4sum

k-sum问题都可以有2-sum引申出来解决,但是时间复杂度为O(n^k-1)。应该要用哈希解决才好的,之后再看看class Solution{private: vector > ans;public: vector >fourSum(vector &num, int target){ sort(num.begin(),num.end()); ans.clear()

2015-01-16 23:34:00 516

原创 Maximal Rectangle

求一个01二位数组最大的矩阵,把它化为直角图再一行一行地算class Solution{public: int maximalRectangle(vector > &martix){ int height[1000][1000]; int maxx = -1; int row = martix.size(); if(row == 0) return 0;

2015-01-12 15:34:50 634

原创 各种排序的实现与复杂度分析(持续更新)

稳定性:选择排序、快速排序、希尔排序、堆排序不是稳定的排序算法,冒泡排序、插入排序、归并排序和基数排序是稳定的排序算法。复杂度冒泡法:  复杂度为O(n*n)。当数据为正序,将不会有交换。复杂度为O(0)。不说了。直接插入排序:O(n*n)希尔排序:算法的复杂度为n的1.2次幂选择排序:O(n*n)快速排序:不稳定,平均时间复杂度O(nlogn),最坏情况时间复杂度为O(n...

2015-01-10 00:45:32 977

原创 Minimum Window Substring

双指针思想,尾指针不断往后扫,当扫到有一个窗口包含了所有T的字符,然后再收缩头指针,直到不能再收缩为止。最后记录所有可能的情况中窗口最小的

2015-01-08 23:09:55 527

原创 linux下c的线程池

c下实现线程池#include #include #include #include #include #include typedef struct worker { void *(*process) (void *arg); void *arg; struct worker *next;} CThread_worker;typedef struc

2015-01-08 01:12:59 943

原创 C++内存分配

一个程序一般分为3段:text段,data段,bss段text段:就是放程序代码的,编译时确定,只读,data段:存放在编译阶段(而非运行时)就能确定的数据,可读可写就是通常所说的静态存储区,赋了初值的全局变量和静态变量存放在这个区域,常量也存放在这个区域bss段:定义而没有赋初值的全局变量和静态变量,放在这个区域一个由C/C++编译的程序占用的内存分为以下几个部分 1、栈区(stack)―

2015-01-06 19:55:35 787

原创 Sudoku Solver

解决数独问题class Solution {public: bool isValid(vector >&board, int a, int b){ for(int i = 0; i < 9; i++) if(i != a && board[i][b] == board[a][b]) return false;

2015-01-06 00:17:20 1017

转载 海量数据处理

教你如何迅速秒杀掉:99%的海量数据处理面试题作者:July出处:结构之法算法之道blog前言   一般而言,标题含有“秒杀”,“99%”,“史上最全/最强”等词汇的往往都脱不了哗众取宠之嫌,但进一步来讲,如果读者读罢此文,却无任何收获,那么,我也甘愿背负这样的罪名,:-),同时,此文可以看做是对这篇文章:十道海量数据处理面试题与十个方法大总结的一般抽象性总结。   

2015-01-03 10:38:30 474

原创 Clone Graph

图的复制class Solution {public: UndirectedGraphNode *cloneGraph(UndirectedGraphNode *node ){ unordered_mapmap; if(node == NULL) return NULL; return clone(node,ma

2015-01-01 19:59:22 651

空空如也

空空如也

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

TA关注的人

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