知之可否

Be yourself; everyone else is already taken.​

lintcode: Word Ladder

Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that:Only one letter c...

2016-03-31 17:43:35

阅读数:431

评论数:0

lintcode:Topological Sorting

Given an directed graph, a topological order of the graph nodes is defined as follow:For each directed edge A -> B in graph, A must before B in th...

2016-03-30 17:27:51

阅读数:349

评论数:0

lintcode:Combination Sum

Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeat...

2016-03-29 23:05:02

阅读数:373

评论数:0

lintcode: Combinations

Given two integers n and k, return all possible combinations of k numbers out of 1 … n.Example For example, If n = 4 and k = 2, a solution is: [[2...

2016-03-29 17:43:36

阅读数:337

评论数:0

C++ unique函数

类属性算法unique的作用是从输入序列中“删除”所有相邻的重复元素。该算法删除相邻的重复元素,然后重新排列输入范围内的元素,并且返回一个迭代器(容器的长度没变,只是元素顺序改变了),表示无重复的值范围得结束。// sort words alphabetically so we can find ...

2016-03-29 15:07:36

阅读数:604

评论数:0

一个进程在内存中的布局

值得一提的是:在C#中struct存放在栈区,class存放在堆区,所以一般struct要比class要快的。   堆和栈的比较表(仅针对C++)   栈(Stack) 堆(Heap) 申请方式 由OS自动分...

2016-03-29 10:00:52

阅读数:1478

评论数:0

const、static变量存放位置

我们将以下面的例子介绍const变量和static变量的存放位置:static int val_a = 1 ; // 初始化的静态变量 int val_b = 2 ; // 全局变量 const int val_c = 3 ; // const 全局变量 static int...

2016-03-29 09:58:05

阅读数:6170

评论数:0

lintcode:Binary Tree Serialization

Design an algorithm and write code to serialize and deserialize a binary tree. Writing the tree to a file is called ‘serialization’ and reading back ...

2016-03-28 23:15:21

阅读数:329

评论数:0

Remove Node in Binary Search Tree

Given a root of Binary Search Tree with unique value for each node. Remove the node with given value. If there is no such a node with given value in ...

2016-03-28 21:41:45

阅读数:434

评论数:0

const指针与指向const对象的指针

1.const指针是一种指针,此指针指向的地址是不能够改变的,但是其指向的对象是可以被修改的,其定义类似: int* const p=地址; 比如下面的代码:int b=12; int* const a=&b; void tes() { *a=1...

2016-03-28 15:10:41

阅读数:265

评论数:0

const的用法,特别是用在函数前面与后面的区别!

const的用法,特别是用在函数后面在普通的非 const成员函数中,this的类型是一个指向类类型的 const指针。可以改变this所指向的值,但不能改变 this所保存的地址。 在 const成员函数中,this的类型是一个指向 const类类型对象的 const指针。既不能改变 this...

2016-03-28 15:08:15

阅读数:3432

评论数:1

c++ 函数返回引用

c++ primer p215一,c++函数的返回分为以下几种情况1)主函数main的返回值:这里提及一点,返回0表示程序运行成功。2)返回非引用类型:函数的返回值用于初始化在跳用函数出创建的临时对象。用函数返回值初始化临时对象与用实参初始化形参的方法是一样 的。如果返回类型不是引用,在调用函数的...

2016-03-28 10:22:27

阅读数:287

评论数:0

显式构造函数

1.什么是显式构造函数?首先要理解什么是隐式构造函数,并且弄清它的优缺点。#include <iostream> using std::cout; using std::endl;class complexNumbers { double real, img; public: ...

2016-03-28 09:36:43

阅读数:390

评论数:0

C++依次读取文件中的字符串——getline()函数的应用

getlime()有着两种形式http://www.cplusplus.com/reference/string/string/getline/ (1) istream& getline (istream& is, string& str, char delim); ...

2016-03-23 22:22:21

阅读数:4302

评论数:0

lintcode: Search Range in Binary Search Tree

Given two values k1 and k2 (where k1 < k2) and a root pointer to a Binary Search Tree. Find all the keys of tree in range k1 to k2. i.e. print all...

2016-03-22 21:38:50

阅读数:303

评论数:0

lintcode:Binary Tree Level Order Traversal

Given a binary tree, return the level order traversal of its nodes’ values. (ie, from left to right, level by level).Challenge 1: Using only 1 queue ...

2016-03-22 21:10:42

阅读数:256

评论数:0

lintcode: Construct Binary Tree from Preorder and Inorder Traversal

Given preorder and inorder traversal of a tree, construct the binary tree.我以前的博文已有介绍构造二叉树/** * Definition of TreeNode: * class TreeNode { * public...

2016-03-22 20:28:17

阅读数:216

评论数:0

洗牌算法:随机打乱一组数

扑克牌洗牌是我们生活中比较喜欢玩的一个游戏。那么我们有没有什么办法自己设计一个扑克牌洗牌的方法呢?在c运行库当中有一个随机函数rand,它可以生成0~32767之间的任意数。那么有没有可能利用这么一个函数对我们扑克牌进行随即洗牌呢?     在这里我抛砖引玉一下,谈一谈自己目前已经看到的两个...

2016-03-22 15:57:35

阅读数:830

评论数:0

lintcode: 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 dept...

2016-03-20 23:04:14

阅读数:295

评论数:0

lintcode:Validate Binary Search Tree

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 only ...

2016-03-20 20:34:49

阅读数:303

评论数:0

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