0%

这一部分主要介绍C++面向对象,多个类之间的关系。另外介绍了虚函数及其实现机制和一些设计模式。

  • Inheritance 继承 is-a
  • Composition 复合 has-a
  • Delegation 委托
阅读全文 »

C++书籍推荐

  1. 语言:C++ Primer, <the C++ programming lauguage>
  2. 经验:effective C++ 系列
  3. 标准库:the C++ standard library STL 源码解析

本文主要介绍C++中的类的基础,通过complex和string两个类介绍类的基础构成和规范写法。主要包括构造函数,拷贝、赋值构造函数,穿插一些小知识点,比如头文件、单例模式、内存管理等知识。

阅读全文 »

题目

http://www.sohu.com/a/153858619_466939
这里有一个漫画,解释的很清楚,算是比较好的动态规划算法入门资料了。
里面有两道经典的习题,爬梯子和挖金矿。分别是一维和二维的情况。

动态规划的三要素:

  1. 最优子结构
  2. 状态转换方程
  3. 边界条件

对应的算法有以下几种:

  1. 暴力法,一般时间复杂度较高
  2. 递归的方法(算法树),复杂度一般是O(2^n)
  3. 备忘录的方法 时空都是O(n)
  4. 自底向上填表,空间复杂度O(1)
阅读全文 »

题目

Given an array arr of integers (not necessarily distinct), we split the array into some number of “chunks” (partitions), and individually sort each chunk. After concatenating them, the result equals the sorted array.

What is the most number of chunks we could have made?

阅读全文 »

题目

In LOL world, there is a hero called Teemo and his attacking can make his enemy Ashe be in poisoned condition. Now, given the Teemo’s attacking ascending time series towards Ashe and the poisoning time duration per Teemo’s attacking, you need to output the total time that Ashe is in poisoned condition.

You may assume that Teemo attacks at the very beginning of a specific time point, and makes Ashe be in poisoned condition immediately.

看着很复杂,实际上就是给一串时间点,给一个作用时间,计算Teemo的总的作用时间。

阅读全文 »

题目

Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.

Find all the elements that appear twice in this array.

Could you do it without extra space and in O(n) runtime?

阅读全文 »

题目

A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same element.

Now given an M x N matrix, return True if and only if the matrix is Toeplitz.

大意就是说如果一个矩阵的每个斜着对角线上的数都相同的话,这个矩阵是Toeplitz矩阵。

阅读全文 »

题目

把一个二维数组转换成r*c的数组。
举例:

原数组[[1,2],[3,4]],现在要转成1*4的[[1,2,3,4]]。
如果不满足转的条件,就返回原数组。

阅读全文 »

题目

Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), …, (an, bn) which makes sum of min(ai, bi) for all i from 1 to n as large as possible.

Note:

  1. n is a positive integer, which is in the range of [1, 10000].
  1. All the integers in the array will be in the range of [-10000, 10000].
阅读全文 »