自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

位置不能带来自由,能力才能让人自由

  • 博客(38)
  • 收藏
  • 关注

原创 Minimum Depth of Binary Tree

Given 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.关键思路:最短的含叶子节点子树,考虑如何缓存树的高度/** * D

2015-10-31 00:33:47 297

原创 Balanced Binary Tree

Given 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 of every node never diffe

2015-10-30 14:39:34 333

转载 gdb寻找死锁

据说再高的高手在写多线程程序的时候都难确保不会产生死锁,死锁的调试也就成为一个比较常见的问题,假设有下面这样一个问题:  一个正在生产环境下运行的进程死锁了,或者你只是在跑一个程序,并没有在调试器里面打开它,然后发现没有响应,日志输出也停止了。由于你是一个有经验的程序员,会想到“我刚刚加上了新的锁策略,不一定稳定,这可能是死锁了“。但是你不想就这么杀掉进程,因为多线程的 bug 不容易重现

2015-10-29 21:01:38 1321

原创 一个数组a[0...n-1],求a[j]-a[i]的最大值,其中i<j

其中数组a[n]是无序的,求a[j]-a[i]的最大值,且i第一种方法:从左往右求下标0到 k - 1 的最小值MIN从右往左求 下标k到n -1 的最大值MAX对于每个k都有一个MAX - MIN的值,最后求这个值的最大值即可。例如数组:4 5 2 6 3 1K:1 2 3 4 5MIN: 4 4 2 2 2MAX:6 6 6 3 1MAX - MIN,最

2015-10-29 19:32:42 2886

原创 Missing Number

Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.For example,Given nums = [0, 1, 3] return 2.Note:Your algorithm should

2015-10-29 00:59:32 284

原创 Search a 2D Matrix II

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 in ascending from left to right.Integers in ea

2015-10-29 00:30:56 311

原创 Peeking Iterator

Given an Iterator class interface with methods: next() and hasNext(), design and implement a PeekingIterator that support the peek() operation -- it essentially peek() at the element that will be retu

2015-10-29 00:18:15 322

原创 给一个数轴,包括正无穷和负无穷,从原点0开始向目标位置x走动(x为整数),第i步,步长为i,求到x的最少步数

给一个数轴,包括正无穷和负无穷,从原点0开始向目标位置x走动(x为整数),第i步,步长为i(可以正向,也可以负向),如 从0 开始,目标地址为3,中途经过(0 ,1),(1 , 3).如果目标地址是2 中途经过(0, 1)(1, -1)(-1, 2),问从0到x的最短路径

2015-10-28 21:12:57 1672

原创 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 array return

2015-10-28 17:44:52 384

原创 Game of Life

According to the Wikipedia's article: "The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970."Given a board with m by

2015-10-28 00:05:27 292

原创 Ugly Number

Write a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly since

2015-10-27 16:04:17 267

原创 Add Digits

Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one

2015-10-27 15:54:35 255

原创 Basic Calculator

Implement a basic calculator to evaluate a simple expression string.The expression string may contain open ( and closing parentheses ), the plus + or minus sign -, non-negative integers and empty

2015-10-23 22:02:42 350

原创 Valid Anagram

Given two strings s and t, write a function to determine if t is an anagram of s.For example,s = "anagram", t = "nagaram", return true.s = "rat", t = "car", return false.Note:You may ass

2015-10-23 14:12:54 289

原创 给定一个无序数组,请调整该数组,调整成奇数放在数组的左边,偶数放在数组的右边。但是奇数与奇数之间的相对顺序不变,偶数和偶数之间的相对顺序也不变。

给定一个无序数组,请调整该数组,调整成奇数放在数组的左边,偶数放在数组的右边。但是奇数与奇数之间的相对顺序不变,偶数和偶数之间的相对顺序也不变。要求思考:如果额外空间复杂度必须为O(1),时间复杂度可以做到什么程度呢?这个题,要保证额外空间复杂度为o(1)的情况下,时间复杂度只能做到o(n^2) ,利用快排思想并不能保证稳定性,利用归并思想做不到常量空间

2015-10-23 13:50:50 1188

原创 满足条件的周长最短的三条边

1.已知一个数组,从数组中取三个数a , b , c满足 a b c可以构成一个三角形,找出 a + b + c最大的三个数,要求时间复杂度为O(nlgn)算法思路:(1)先将数组排序(nlgn)(2)从数组最后一个元素开始,向前遍历,如果 a + b > c, 则即为所求,(3)否则 以倒数第二个元素为最大边( 注a b不再向前滑动,因为 前面的元素更不可能满足构成三角形条件),

2015-10-21 23:15:28 567

原创 First Bad Version

You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the

2015-10-20 23:27:50 291

原创 Perfect Squares

Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n.For example, given n = 12, return 3 because 12 = 4 + 4 + 4; given n = 13,

2015-10-20 13:56:36 295

原创 Move Zeroes

Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.For example, given nums = [0, 1, 0, 3, 12], after calling your

2015-10-19 18:31:41 254

原创 Summary Ranges

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: string format(int

2015-10-19 14:25:06 265

原创 Find the Duplicate Number

Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number, fi

2015-10-19 12:43:29 366

原创 Word Pattern

Given a pattern and a string str, find if str follows the same pattern.Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str.

2015-10-17 14:54:15 328

原创 Nim Game

You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will be the

2015-10-17 09:09:13 348

原创 Vmware中安装ubuntu无法通过NAT上网

关闭虚拟机后,打开主界面里的     编辑——编辑网络参数,在最左下角有一个“恢复默认”,点击后让其重新分配子网IP地址,完毕后重新打开Linux就行了

2015-10-12 00:10:13 482

原创 10.11笔试时遇到的知识点总结

2015-10-11 21:26:03 446

原创 内存

下面是关于内存,地址空间,寻址能力(最小存储单元)之间的关系

2015-10-10 09:17:19 319

原创 物理存储器和内存地址空间

物理存储器和存储地址空间是两个不同的概念。但是由于这两者有十分密切的关系,而且两者都用B、KB、MB、GB来度量其容量大小,因此容易产生认识上的混淆。初学者弄清这两个不同的概念,有助于进一步认识主存储器和用好主存储器。物理存储器是指实际存在的具体存储器芯片。如主板上装插的主存条和装载有系统的BIOS的ROM芯片,显示卡上的显示RAM芯片和装载显示BIOS的ROM芯片,以及各种适配卡上的RAM芯

2015-10-08 18:47:36 1309

原创 位,字节,字的区别

1、位(bit) 来自英文bit,音译为“比特”,表示二进制位。位是计算机内部数据储存的最小单位,11010100是一个8位二进制数。一个二进制位只可以表示0和1两种状态(21);两个二进制位可以表示00、01、10、11四种(22)状态;三位二进制数可表示八种状态(23)……。 2、字节(byte) 字节来自英文Byte,音译为“拜特”,习惯上用大写的“B”表示。 字节是计算机中

2015-10-07 18:18:30 694

原创 TCP性能的考虑

2015-10-07 10:51:35 558

原创 Word Ladder

Given two words (beginWord and endWord), and a dictionary's word list, find the length of shortest transformation sequence from beginWord to endWord, such that:Only one letter can be changed at a

2015-10-07 10:32:24 259

原创 程序的机器级表示3.7

2015-10-05 21:44:30 331

原创 程序的机器级表示3.4

2015-10-05 15:14:34 345

原创 Regular Expression Matching

Implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the ent

2015-10-04 10:53:55 287

转载 weak_ptr的用处

看到一篇关于weak_ptr的好文weak_ptr是为配合shared_ptr而引入的一种智能指针,它更像是shared_ptr的一个助手,而不是一个智能指针。它的最大作用在于协助shared_ptr工作,像旁观者那样观测资源的使用情况。weak_ptr被设计为与shared_ptr协同工作,可以从一个shared_ptr或者另外一个weak_ptr对象构造,获得资源的观测权限。但weak_p

2015-10-03 18:22:05 2085

原创 右值引用

#include #include using namespace std;class People{public: People() { cout << "People()" << endl; } People(const string &name) : name_(name) { cout << "

2015-10-02 23:33:27 452

原创 shared_ptr

using namespace std;class Test{public: Test() { cout << "Test" << endl;} ~Test() { cout << "~Test" << endl;}private: Test(const Test &); void operator=(const Test &);};int mai

2015-10-02 22:28:05 281

原创 unique_ptr

#include #include #include #include using namespace std;class Test{public: Test() { cout << "Test" << endl;} ~Test() { cout << "~Test" << endl;}};int main(int argc, const char *argv

2015-10-02 22:25:46 349

原创 函数适配器

#include #include #include #include using namespace std;void foo(const string &s){ cout << s << endl;}int main(int argc, const char *argv[]){ void (*pFunc) (const string &) = &foo;

2015-10-02 21:44:11 411

空空如也

空空如也

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

TA关注的人

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