2017年6月8日

(leetcode题解)Reshape the Matrix

摘要: In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a new one with different size but keep its original data. 阅读全文

posted @ 2017-06-08 19:52 kiplove 阅读(240) 评论(0) 推荐(0) 编辑

(leetcode题解)Search Insert Position

摘要: Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in or 阅读全文

posted @ 2017-06-08 16:51 kiplove 阅读(135) 评论(0) 推荐(0) 编辑

2017年6月7日

(leetcode题解)Array Partition I

摘要: 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 阅读全文

posted @ 2017-06-07 19:42 kiplove 阅读(167) 评论(0) 推荐(0) 编辑

(leetcode题解)Merge Sorted Array

摘要: Given 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 tha 阅读全文

posted @ 2017-06-07 16:41 kiplove 阅读(149) 评论(0) 推荐(0) 编辑

(leetcode题解)Top K Frequent Elements

摘要: Given a non-empty array of integers, return the k most frequent elements. For example,Given [1,1,1,2,2,3] and k = 2, return [1,2]. Note: You may assum 阅读全文

posted @ 2017-06-07 15:51 kiplove 阅读(189) 评论(0) 推荐(0) 编辑

2017年6月6日

强制类型转换

摘要: 命名的强制类型转换 static_cast 形式:static_cast < type-id > ( expression ) 任何具有明确意义的类型转换,只要不包括底层const(指针所指的对象是常量),都可以使用static_cast。 使用场景 1、把一个较大的算术类型赋给一个较小 2、voi 阅读全文

posted @ 2017-06-06 16:39 kiplove 阅读(394) 评论(0) 推荐(0) 编辑

2017年6月4日

单源最短路径

摘要: 一、Dijkstra算法 Dijkstra算法是解决带权重的有向图最短路径问题,要求所有边权重为非负值。 以下是算法导论上给出的伪码,采用了是贪心策略实现的,总是寻找集合V-S(S集合是加入)中最近的节点加入到S集合中,算法时间复杂度依赖于最小优先队列的实现方式。 下面是C++的实现,时间复杂度是O 阅读全文

posted @ 2017-06-04 21:10 kiplove 阅读(3558) 评论(0) 推荐(0) 编辑

2017年5月27日

copy构造函数

摘要: copy构造函数定义 copy构造函数的定义:如果一个构造函数的第一个参数是自身类类型的引用,且额外参数都是默认值,则此构造函数时copy构造函数(摘自c++primer)。 copy构造函数的形参必须引用类型:如果不是引用类型,为了调用copy构造函数,必须copy他的实参,但copy实参又需要c 阅读全文

posted @ 2017-05-27 17:28 kiplove 阅读(485) 评论(0) 推荐(0) 编辑

2017年5月26日

namespace 命名空间

摘要: 一、命名空间的定义 namespace 命名空间的名字 {类/变量/函数/模板/其他命名空间}; 命名空间空间可以定义在全局作用域和其他命名空间中,但不能定义在函数或类的内部。 二、命名空间的作用域 每一个命名空间都是一个作用域,定义在某个命名空间中的名字可以被该命名空间内的其他成员访问,也可以被这 阅读全文

posted @ 2017-05-26 21:30 kiplove 阅读(273) 评论(0) 推荐(0) 编辑

2017年5月8日

日常编程练习(四)

摘要: 栈是先进后出,队列是先进先出 一、两个栈实现队列 只要考虑一个栈作为输入,另一个栈作为输出即可 二、两个队列实现栈 两个队列无论怎么转换先进先出的顺序是不会改变的,所以队顶的数永远是最后输出,因而每次输入直接加到有值队列即可,输出时获取有值队列最后一个值,并将之前的转换到另一个队列。 阅读全文

posted @ 2017-05-08 15:48 kiplove 阅读(198) 评论(0) 推荐(0) 编辑

导航