- 博客(135)
- 收藏
- 关注
转载 97. Interleaving String
DescriptionGiven s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.ExampleGiven:s1 = "aabcc",s2 = "dbbca",When s3 = "aadbbcbcac", return true.When s3 = "aadbbbaccc", r...
2017-11-01 20:22:00
220
转载 Leetcode: 96. Unique Binary Search Trees
DescriptionGiven n, how many structurally unique BST's (binary search trees) that store values 1...n?ExampleGiven n = 3, there are a total of 5 unique BST's. 1 3 3 2 1...
2017-06-22 09:32:00
212
转载 Leetcode: 95. Unique Binary Search Trees II
DescriptionGiven an integer n, generate all structurally unique BST's (binary search trees) that store values 1...n.ExampleGiven n = 3, your program should return all 5 unique BST's shown belo...
2017-06-22 09:30:00
229
转载 Leetcode: 94. Binary Tree Inorder Traversal
DescriptionGiven a binary tree, return the inorder traversal of its nodes' values.ExampleGiven binary tree [1,null,2,3],1 \ 2 /3return [1,3,2].Note: Recursive solution is trivial, c...
2017-06-21 20:27:00
187
转载 Leetcode: 93. Restore IP Addresses
DescriptionGiven a string containing only digits, restore it by returning all possible valid IP address combinations.ExampleGiven "25525511135",return ["255.255.11.135", "255.255.111.35"]. (...
2017-06-21 17:20:00
100
转载 Leetcode: 92. Reverse Linked List II
DescriptionReverse a linked list from position m to n. Do it in-place and in one-pass.ExampleGiven 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2->5->NU...
2017-06-21 15:43:00
124
转载 Leetcode: 91. Decode Ways
DescriptionA message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, det...
2017-06-21 10:44:00
89
转载 Leetcode: 90. Subsets II
DescriptionGiven a collection of integers that might contain duplicates, nums, return all possible subsets.Note: The solution set must not contain duplicate subsets.ExampleIf nums = [1,2,2], ...
2017-06-20 23:07:00
90
转载 Linux写时拷贝技术(copy-on-write)
不经意间看到这篇帖子,想起实习面试的时候再讨论fork时,谈到了这个问题。做一个记录吧。原帖见:Linux写时拷贝技术(copy-on-write)COW技术初窥在linux程序中,fork()会产生一个和父进程完全相同的子进程,但子进程在此后多会exec系统调用,出于效率考虑,linux中引入了“写时复制”技术,也就是只有进程空间的各段的内容要发生变化时,才将父进程的内容复制一份...
2017-06-20 16:27:00
235
转载 基本UDP套接字编程
概述使用TCP编写的应用程序和使用UDP编写的应用程序之间存在一些本质差异,其原因在于这两个传输层之间的差别:UDP是无连接不可靠的数据报协议,非常不同于TCP提供的面向连接的可靠字节流。然而相比TCP,有些场合更适合UDP。使用UDP编写的一些常见应用程序有:DNS(域名系统)、NFS(网络文件系统)和SNMP(简单网络管理协议)。下图给出了典型的UDP客户/服务器程序的函数调用。...
2017-06-20 15:17:00
107
转载 Leetcode: 87. Scramble String
DescriptionGiven a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation of s1 = "great": great ...
2017-06-15 10:39:00
128
转载 Leetcode: 89. Gray Code
DescriptionThe gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print th...
2017-06-15 10:38:00
103
转载 Leetcode: 88. Merge Sorted Array
DescriptionGiven two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:You may assume that nums1 has enough space (size that is greater or equal to m + n) ...
2017-06-14 11:04:00
98
转载 Leetcode: 86. Partition List
DescriptionGiven a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order of the no...
2017-06-14 10:50:00
119
转载 Leetcode: 85. Maximal Rectangle
DescriptionGiven a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area.ExampleGiven the following matrix: 1 0 1 0 0 1 0 1 1 1...
2017-06-13 22:19:00
119
转载 Leetcode: 84. Largest Rectangle in Histogram
DescriptionGiven n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.ExampleGiven heights = [...
2017-06-13 22:04:00
110
转载 深入探索C++对象模型(七)
站在对象模型的尖端(On the Cusp of the Object Model)Template下面是有关template的三个主要讨论方向:template的声明,基本上来说就是当你声明一个template class、template class member function等等,会发生什么事情。如何"具现(instantiates)"出class object以及i...
2017-06-13 20:50:00
204
转载 深入探索C++对象模型(六)
执行期语意学(Runtime Semantics)对象的构造和析构(Object Constructor and Destructor)一般而言,constructor和destructor的安插都如你所预期:{ Point point; //point.Point::Point() 一般而言会被安插在这里 ... //point.Point::~...
2017-06-12 11:17:00
265
转载 深入探索C++对象模型(五)
构造、解构、拷贝语意学(Semantics of Construction,Destruction, and Copy)一般而言,class的data member应该被初始化,并且只在constructor中或是在class的其他member functions中指定初值。其他任何操作都将破坏封装性质,使class的维护和修改更加困难。纯虚函数的存在(Presence of a P...
2017-06-09 09:46:00
249
转载 深入探索C++对象模型(四)
Function语意学(The Semantics of Function)static member functions不可能做到的两点:(1)直接存取nonstatic数据,(2)被声明为const的。Member的各种调用方式Nonstatic Member Functions(非静态成员函数)C++的设计准则之一就是:nonstatic member function至少...
2017-06-07 21:45:00
187
转载 Leetcode: 83. Remove Duplicates from Sorted List
DescriptionGiven a sorted linked list, delete all duplicates such that each element appear only once.ExampleGiven 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2...
2017-06-06 22:06:00
83
转载 Leetcode: 82. Remove Duplicates from Sorted List II
DescriptionGiven a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.ExampleGiven 1->2->3->3->4->4->5, re...
2017-06-06 21:56:00
104
转载 深入探索C++对象模型(三)
Data 语义学一个class的data members,一般而言,可以表现这个class在程序执行时的某种状态。Nonstatic data members放置的是“个别的class object”感兴趣的数据,static data members则放置的是“整个class”感兴趣的数据。C++对象模型尽量以空间优化和存取速度优化的考虑来表现nonstatic data memb...
2017-06-06 20:04:00
174
转载 深入探索C++对象模型(二)
构造函数语义学(The Semantics of Constructors)Default Constructor的构造操作对于class X,如果没有任何user-declared constructor,那么会有一个default constructor被隐式(implicitly)声明出来...一个被隐式声明出来的default constructor将是一个trivial(浅...
2017-06-06 10:14:00
254
转载 Leetcode: 81. Search in Rotated Sorted Array II
DescriptionFollow up for "Search in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Suppose an array sorted in ascending order is r...
2017-06-05 15:20:00
69
转载 深入探索C++对象模型(一)
再读《深入探索C++对象模型》笔记。关于对象C++在加入封装后(只含有数据成员和普通成员函数)的布局成本增加了多少?答案是并没有增加布局成本。就像C struct一样,memeber functions虽然含在class的声明之内,却不出现在object中。每一个non-inline member function只会诞生一个函数实体。至于每一个“拥有零个或一个定义的” inli...
2017-06-05 11:23:00
97
转载 内存池的设计与实现
目的内存池的作用在于消除频繁调用系统默认的内存分配和释放函数所带来的开销问题。由于每次要求分配的内存大小不等,使用默认的内存分配函数的话,可能给系统带来大量的碎片问题,所以,将内存配置问题交给底层的内存池去处理,是一个不错的选择。设计本来打算自己实现一个内存池,想了想还是算了。总结这篇文章的目的在于深入剖析内存池相关内容,主要是相关思想,而不在于代码实现上。所以,通过STL的底层...
2017-06-02 15:44:00
117
转载 Leetcode: 80. Remove Duplicates from Sorted Array II
DescriptionFollow up for "Remove Duplicates":What if duplicates are allowed at most twice?ExampleGiven sorted array nums = [1,1,1,2,2,3],Your function should return length = 5, with the fir...
2017-06-01 23:07:00
82
转载 Leetcode: 79. Word Search
DescriptionGiven 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...
2017-06-01 22:49:00
94
转载 Leetcode: 78. Subsets
DescriptionGiven a set of distinct integers, nums, return all possible subsets.Note: The solution set must not contain duplicate subsets.ExampleIf nums = [1,2,3], a solution is:[ [3], ...
2017-06-01 22:05:00
82
转载 Leetcode: 77. Combinations
DescriptionGiven two integers n and k, return all possible combinations of k numbers out of 1 ... n.ExampleIf n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], ...
2017-06-01 20:33:00
97
转载 C/C++内存分区
随手搜的一个问题,本来只是想印证一下自己的想法,怎料这个问题居然还有这么多不同的说法。根据网上的资料和我自己的观点,总结如下:在C/C++中内存分为五个区:栈区、堆区、(自由存储区、)全局/静态存储区和常量存储区栈区通常是局部变量和函数参数,由编译器自动分配释放堆区本来在我的理解中,动态分配的内存都应该在堆区,即new和malloc的内存都在此,现在才发现是把C和C++...
2017-06-01 10:07:00
86
转载 Leetcode: 76. Minimum Window Substring
DescriptionGiven a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example,S = "ADOBECODEBANC"T = "ABC"Minimum window ...
2017-06-01 09:10:00
103
转载 Leetcode: 75. Sort Colors
DescriptionGiven 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...
2017-05-31 20:42:00
96
转载 Leetcode: 74. Search a 2D Matrix
DescriptionWrite 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 int...
2017-05-31 20:19:00
96
转载 Leetcode:73. Set Matrix Zeroes
DescriptionGiven a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.思路在原数组上面做,如果matrix[i][j] = 0, 由于第i行,第j列都要变成0,所以将matrix[i][0] = 0, matrix[0][j] = 0,这表明将...
2017-05-31 19:33:00
64
转载 Leetcode:72. Edit Distance
DescriptionGiven two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permit...
2017-05-30 19:00:00
88
转载 Leetcode:71. Simplify Path
DescriptionGiven an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"Corner Cases:Did you consider the case ...
2017-05-30 17:13:00
78
转载 Leetcode:70. Climbing Stairs
DescriptionYou are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Note: Given n wil...
2017-05-30 16:05:00
98
转载 Leetcode:69. Sqrt(x)
DescriptionImplement int sqrt(int x).Compute and return the square root of x.思路二分查找代码class Solution {public: int mySqrt(int x) { if (x < 0) return INT_MIN; if (x &l...
2017-05-30 15:56:00
104
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人