摘要:
注:本文代码测试环境为win7 X64 cpu, 编译器为gcc4.7.1 和 vs2010 内存对齐是编译器为了便于CPU快速访问而采用的一项技术 我们先从一个例子开始,对下面的类(或者结构体) class node { char c; int i; short s; }no; sizeof(no)的值是多少呢,如果你的回答是7(1+4+2),那么你应该认... 阅读全文
摘要:
程序Crash调试方式--MAP文件vs2010利用map,cod文件定位崩溃代码行调试Release发布版程序的Crash错误VS2005(vs2008,vs2010)使用map文件查找程序崩溃原因 阅读全文
摘要:
草原和大树:Debug和Release区别ithzhang:Debug与Release版本的区别详解 阅读全文
摘要:
问题:两个已经排好序的数组,找出两个数组合并后的中位数(如果两个数组的元素数目是偶数,返回上中位数)。设两个数组分别是vec1和vec2,元素数目分别是n1、n2。算法1:最简单的办法就是把两个数组合并、排序,然后返回中位数即可,由于两个数组原本是有序的,因此可以用归并排序中的merge步骤合并两个... 阅读全文
摘要:
题目链接给定两个正整数a,b,分别定义两个集合L和R,集合L:即把1~a,1~b中整数乘积的集合定义为L = {x * y | x,y是整数且1 b 可以两者交换),a的十进制位数为ka, b的十进制位数为kb。因此异或求解集合R中元素时,只有b的最后ka个二进制位受影响,b的前kb-ka个二进制位可以表示0…2^(kb-ka)-1的所有数。现在我们只考虑b的后面ka个二进制位:1、假设b = 11001,a = 101,那么R = {00001…11001}^{001…101}表示的数有哪些呢? 我们可以看到两者异或后可以表示的最大的数是11001^100 = 11101(注意到后三位异或. 阅读全文
摘要:
题目如下甲乙两个人用一个英语单词玩游戏。两个人轮流进行,每个人每次从中删掉任意一个字母,如果剩余的字母序列是严格单调递增的(按字典序a Map; static int who (string word) { //用map保存子问题,防止重复计算 //amap[s]表示字符串s由甲操作时甲能否获胜 //bmap[s]表示字符串s由乙操作时甲能否获胜 Map amap, bmap; return (int)dfs(word, 1, amap, bmap); }private: //判断字符串是否严格... 阅读全文
摘要:
题目链接Given two binary strings, return their sum (also a binary string).For example, a = "11" b = "1" Return "100".分析:简单的处理二进制求和和进位即可 本文地址class So... 阅读全文
摘要:
题目链接Validate if a given string is numeric.Some examples: "0" => true " 0.1 " => true "abc" => false "1 a" => false "2e10" => true 本文地址Note... 阅读全文
摘要:
题目链接Given a number represented as an array of digits, plus one to the number分析:too simple 本文地址class Solution {public: vector plusOne(vector &digits... 阅读全文
摘要:
题目链接Given an array of words and a length L, format the text such that each line has exactly L characters and is fully (left and right) justified.You s... 阅读全文
摘要:
题目链接Implement int sqrt(int x).Compute and return the square root of x.面试时需要考虑x是否小于0.分析:牛顿法,先假设一个初始解res(本文设为1),然后以抛物y = x^2-c(这里的c相当于题目中的x)上的点(res, res... 阅读全文
摘要:
题目链接You 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... 阅读全文
摘要:
题目链接Given an absolute path for a file (Unix-style), simplify it.For example, path = "/home/", => "/home" path = "/a/./b/../../c/", => "/c"Corner Ca... 阅读全文
摘要:
题目链接Given 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 ha... 阅读全文
摘要:
题目链接Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.Follow up:Did you use extra space? A straight forward... 阅读全文
摘要:
LeetCode:Search in Rotated Sorted ArraySuppose 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... 阅读全文
摘要:
题目链接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 sorte... 阅读全文
摘要:
题目链接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 r... 阅读全文
摘要:
题目链接Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.For example, If n = 4 and k = 2, a solution is:[ [2,4], ... 阅读全文
摘要:
题目链接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 "ad... 阅读全文
摘要:
LeetCode:Remove Duplicates from Sorted ListGiven a sorted linked list, delete all duplicates such that each element appear only once.For example, Give... 阅读全文
摘要:
LeetCode:Remove Duplicates from Sorted ArrayGiven a sorted array, remove the duplicates in place such that each element appear only once and return th... 阅读全文
摘要:
题目链接Given 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 = "ADOB... 阅读全文
摘要:
本文介绍c++里面的四个智能指针: auto_ptr, shared_ptr, weak_ptr, unique_ptr 其中后三个是c++11支持,并且第一个已经被c++11弃用。为什么要使用智能指针:我们知道c++的内存管理是让很多人头疼的事,当我们写一个new语句时,一般就会立即把delete语句直接也写了,但是我们不能避免程序还未执行到delete时就跳转了或者在函数中没有执行到最后的delete语句就返回了,如果我们不在每一个可能跳转或者返回的语句前释放资源,就会造成内存泄露。使用智能指针可以很大程度上的避免这个问题,因为智能指针就是一个类,当超出了类的作用域是,类会自动调用析构函数 阅读全文
摘要:
题目链接Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.分析:一般一个题目我首先会想想怎么暴力解决,比如这一题,可... 阅读全文
摘要:
题目链接Given 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 ... 阅读全文
摘要:
目录 一、概述 二、从一个例子理解线段树 创建线段树 线段树区间查询 单节点更新 区间更新 三、线段树实战 一 概述 线段树,类似区间树,它在各个节点保存一条线段(数组中的一段子数组),主要用于高效解决连续区间的动态查询问题,由于二叉结构的特性,它基本能保持每个操作的复杂度为O(logn)。 线段树 阅读全文
摘要:
题目链接Given a linked list and a valuex, partition it such that all nodes less thanxcome before nodes greater than or equal tox.You should preserve the o... 阅读全文
摘要:
题目链接Given a strings1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representa... 阅读全文
摘要:
题目链接Given two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space to hold additional element... 阅读全文
摘要:
题目链接The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integernrepresenting the total nu... 阅读全文
摘要:
题目链接A message containing letters fromA-Zis being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message c... 阅读全文
摘要:
求集合的所有子集问题LeetCode:SubsetsGiven a set of distinct integers,S, return all possible subsets.Note:Elements in a subset must be in non-descending order.Th... 阅读全文
摘要:
题目链接Evaluate the value of an arithmetic expression inReverse Polish Notation.Valid operators are+,-,*,/. Each operand may be an integer or another exp... 阅读全文
摘要:
题目链接Reverse a linked list from positionmton. Do it in-place and in one-pass.For example:Given1->2->3->4->5->NULL,m= 2 andn= 4,return1->4->3->2->5->NUL... 阅读全文
摘要:
题目链接Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given"25525511135",return["2... 阅读全文
摘要:
LeetCode:Unique Binary Search TreesGivenn, how many structurally uniqueBST's(binary search trees) that store values 1...n?For example,Givenn= 3, there... 阅读全文
摘要:
题目链接Givens1,s2,s3, find whethers3is formed by the interleaving ofs1ands2.For example,Given:s1="aabcc",s2="dbbca",Whens3="aadbbcbcac", return true.When... 阅读全文
摘要:
题目链接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 on... 阅读全文
摘要:
先序遍历:http://www.cnblogs.com/TenosDoIt/p/3416824.html中序遍历:http://www.cnblogs.com/TenosDoIt/p/3445449.html后序遍历:http://www.cnblogs.com/TenosDoIt/p/3416835.html层序遍历:http://www.cnblogs.com/TenosDoIt/p/3440542.html 阅读全文