摘要: 题目 You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a sing 阅读全文
posted @ 2016-05-31 17:02 marcusxu 阅读(126) 评论(0) 推荐(0) 编辑
摘要: 题目 Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have 阅读全文
posted @ 2016-05-31 15:07 marcusxu 阅读(178) 评论(0) 推荐(0) 编辑
摘要: 题目 Implement a basic calculator to evaluate a simple expression string. The expression string contains only non-negative integers, +, -, *, / operator 阅读全文
posted @ 2016-05-08 19:09 marcusxu 阅读(203) 评论(0) 推荐(0) 编辑
摘要: 题目 Given an integer matrix, find the length of the longest increasing path. From each cell, you can either move to four directions: left, right, up or 阅读全文
posted @ 2016-04-28 18:54 marcusxu 阅读(208) 评论(0) 推荐(0) 编辑
摘要: 自动对齐快捷键为:ctrl+k+d 按快捷键前,请先将需要对齐的代码选中。不选中是不行的。 阅读全文
posted @ 2016-04-28 16:20 marcusxu 阅读(1642) 评论(0) 推荐(0) 编辑
摘要: 产生随机数在程序中很有用,这篇文章简单介绍一下产生随机数的方法。 伪随机数 使用标准库<cstdlib>中的rand()函数产生随机数。 表面上看,这段程序会产生三个随机数,但一个有趣的事情是,每次程序运行时产生的数据都是相同的。 我每次运行的结果都如下: 可以看出,rand()函数并不会产生一个真 阅读全文
posted @ 2016-04-28 11:11 marcusxu 阅读(2929) 评论(0) 推荐(0) 编辑
摘要: 教科书中失踪的vector 很奇怪的一件事情,在当时学习C++的时候,老师并没有讲授容器的内容,当时参考的谭浩强老师的红皮C++也没有这个内容,不知为何。后来再学C++,发现容器是一个很重要的概念,在C++primer中,大量使用了vector容器,在很多在线编程网站的题目中,也使用了vector< 阅读全文
posted @ 2016-04-26 20:06 marcusxu 阅读(1059) 评论(0) 推荐(0) 编辑
摘要: 问题: Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive. Example:Given nums = [-2, 0, 3, -5, 2, -1] sumRange(0, 2) -> 1 sumRange(2, 5) -> -1 sumRang... 阅读全文
posted @ 2016-04-26 18:57 marcusxu 阅读(459) 评论(0) 推荐(0) 编辑
摘要: 堆 用数组存储一个堆,看成一个近似的完全二叉树。堆有自己的尺寸(不一定与数组长度相同)。 堆的性质:父结点比儿子结点大是最大堆;父节点比儿子节点小是最小堆。 本文以最大堆为例。 对于一个结点i,其父结点标号是i/2向下取整,左子结点是2*i,右子结点是2*i+1。 堆的高度是log(n)。 堆排序的 阅读全文
posted @ 2016-04-18 16:23 marcusxu 阅读(371) 评论(0) 推荐(0) 编辑
摘要: 很早之前便听说过地精排序的名字,今天自己看来一下,发现这是一种非常简单而且有趣的排序算法。 为什么叫地精排序? 地精排序在2000年由Dr. Hamid Sarbazi-Azad 提出的时候被称作 stupid sort,可见其思想的简单性。后来,这个算法被Dick Grune 描述成地精排序Gno 阅读全文
posted @ 2016-04-17 20:50 marcusxu 阅读(1990) 评论(0) 推荐(0) 编辑