- 博客(17)
- 收藏
- 关注
原创 [LeetCode]Two Sum
Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target, whe
2015-10-26 17:01:37 297
原创 STL中 priority_queue的用法
最近要用到queue里的priority_queue,特意去学了下,总结下。priority_queue调用 STL里面的 make_heap(), pop_heap(), push_heap() 算法实现,也算是堆的另外一种形式。先写一个用 STL 里面堆算法实现的与真正的STL里面的 priority_queue用法相似的priority_queue, 以加深对 priority_queu
2015-10-25 15:39:02 276
转载 c/c++内存管理注意的问题
【传说中的林锐博士写的,转载一下】程序员们经常编写内存管理程序,往往提心吊胆。如果不想触雷,唯一的解决办法就是发现所有潜伏的地雷并且排除它们,躲是躲不了的。本章的内容比一般教科书的要深入得多,读者需细心阅读,做到真正地通晓内存管理。7.1内存分配方式内存分配方式有三种: (呵呵,可能和我前面写过的5种内存区域不太一致,不过大致也说的差不多的)(1)从静态存储区域分配。内存在程序
2015-10-23 13:51:37 301
原创 [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 that is greater or equal to m + n) to hold addit
2015-10-22 10:47:52 345
原创 [LeetCode]Pascal's Triangle
Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]分析 要得到一个帕斯卡三角, 我们只需要找到规律即可。
2015-10-21 22:40:33 289
原创 [LeetCode]Plus One
Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list.class Solution66{
2015-10-21 21:51:48 210
原创 [LeetCode]Remove Element
Given an array and a value, remove all instances of that > value in place and return the new length.The order of elements can be changed. It doesn't matter what you leave beyond the new length.
2015-10-21 21:50:16 212
原创 [LeetCode]Search in Rotated Sorted Array
Suppose 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 6 7 0 1 2).You are given a target value to search. If found in the array retur
2015-10-20 13:09:05 309
原创 [LeetCode]Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.分析:递归/** * Definition for
2015-10-20 11:10:27 310
原创 [LeetCode]Add Digits
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has on
2015-10-20 10:47:37 379
原创 关于gt-itm工具在window下使用
最近做网络仿真实验,需要生成网络拓扑文件。常用的一个网络拓扑器是gt-itm工具,但是gt-itm一般都是装在ns2里使用,ns2又是在linux使用的。那么能不能在windows下使用gt-itm呢?本来我也是怀疑的,今天鼓捣了半天,居然还真能使用。 cygwin基于Windows系统中能够使用linux环境(可以百度)。抱着试试看的态度,尝试在我Win10电脑上装了cygwin.关于cy
2015-10-20 00:11:17 2532 1
转载 C++ operator关键字(重载操作符)
http://blog.sina.com.cn/s/blog_4b3c1f950100kker.html
2015-10-17 16:15:36 362
原创 C++中的static关键字
点击打开链接C++的static有两种用法:面向过程程序设计中的static和面向对象程序设计中的static。前者应用于普通变量和函数,不涉及类;后者主要说明static在类中的作用。要理解static,就必须要先理解另一个与之相对的关键字,很多人可能都还不知道有这个关键字,那就是auto,其实我们通常声明的不用static修饰的变量,都是auto的,因为它是默认的,就象sh
2015-10-13 21:09:57 234
原创 c++中vector的用法
一、概述vector是C++标准模板库中的部分内容,它是一个多功能的,能够操作多种数据结构和算法的模板类和函数库。vector是一个容器,它能够存放各种类型的对象,简单地说,vector是一个能够存放任意类型的动态数组,可以动态改变大小。例如:int myHouse[100] ;// c语言风格vector vecMyHouse(100);// 采用vector当如上定义后,v
2015-10-12 14:09:24 798
原创 [LeetCode]Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of converting the integer to string, no
2015-10-08 18:37:02 252
转载 C++ operator关键字(重载操作符)
http://blog.sina.com.cn/s/blog_4b3c1f950100kker.html operator是C++的关键字,它和运算符一起使用,表示一个运算符函数,理解时应将operator=整体上视为一个函数名。 这是C++扩展运算符功能的方法,虽然样子古怪,但也可以理解:一方面要使运算符的使用方法与其原来一致,另一方面扩展其功能只能通过函数的
2015-10-07 10:28:07 280
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人