码迷,mamicode.com
首页 >  
搜索关键字:递归    ( 18847个结果
一道推理题
题目:http://115.28.76.232/problem?pid=1115   题意:初始给定两个完美数1和3,如果都是完美数,那么也是完美数。现在给定一个数,判断它      是否是完美数。   分析:嗯,这道题Mayuyu有两种方法,第一种方法是按照题意有,那么我们进行递归直接判断。      这样做的时间复杂度很高,通过打表对一些数的观察发现,只需要看这个数是否只由3和5组...
分类:其他好文   时间:2014-06-19 10:28:18    阅读次数:166
内部连接和外部连接
声明和定义 声明 是将一个名称引入一个程序. 定义 提供了一个实体在程序中的唯一描述. 声明在单个作用域内可以重复多次(类成员除外),定义在一个给定的作用域内只能出现一次. 一个定义就是一个声明,除非: 它定义了类的一个静态数据成员.它定义了类的非内联成员函数. 内部连接和外部连接 当一个实现文件(.cpp ...)编译时,预处理器(CPP)首先递归的包含头文件,形成一个保...
分类:其他好文   时间:2014-06-16 12:42:05    阅读次数:225
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 repeated number may be chosen from C un...
分类:其他好文   时间:2014-06-15 20:00:18    阅读次数:185
Combination Sum II
题目 Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. Each number in C may only be used once in...
分类:其他好文   时间:2014-06-15 19:24:21    阅读次数:229
Count and Say
题目 The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221, ... 1 is read off as "one 1" or 11. 11 is read off as "two 1s" or 21. 21 i...
分类:其他好文   时间:2014-06-15 18:51:33    阅读次数:220
POJ 3664 Election Time 题解
这道题网上很多人都会说容易,水题之类的话,不过我看了下说这样的话的人的程序,可以说他们的程序都不及格! 为什么呢?因为他们的程序都是使用简单的二次排序水过(大概你能搜索到的多是这样的程序),那样自然可以说不及格了。 因为本题真正的目的是求前k个最大数的问题,这就需要活用快速排序。 求前k个最大数的思路: 1 选取一个数位轴,然后把大于这个数的数放到数列前面,小于这个数的数放到数列后面 2 如果前面的数的数量大于k,那么可以去掉后面的数,递归在前面的数查找前k个最大数 3 如果前面的数的数量小于k,那么截去前...
分类:其他好文   时间:2014-06-15 18:04:07    阅读次数:181
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 order. You may assume no duplicates i...
分类:其他好文   时间:2014-06-15 17:27:16    阅读次数:251
输入N个数,输出所有可能的排列组合(6+个小时啊,耶稣~)
输入N个数,输出所有可能的排列组合           一行代码一行泪。。。手都被发热的笔记本烤的不舒服了。。。。6个多小时过去鸟。。。终于粗来鸟。。。。 昨天同学问到一个排列组合的问题,本身不会很难,原题是固定输入4个数字,例如1 2 3 4,输出所有可能的排列组合 暴力的话应该不难的。代码+debug,半个小时。 如果是输入N个数字呢? 先说简单的暴力方法,如...
分类:其他好文   时间:2014-06-15 17:09:02    阅读次数:282
LeetCode:Path Sum
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum. For example: Given the below bin...
分类:其他好文   时间:2014-06-15 09:34:35    阅读次数:226
每天一个小算法(3)----倒序打印链表
这个比较简单,用栈、递归、倒转链表都可以实现,不再过多解释。代码使用递归实现 1 #include 2 #include 3 #include 4 typedef struct Node 5 { 6 int data; 7 Node* next; 8 }Node, *List;...
分类:其他好文   时间:2014-06-13 15:25:59    阅读次数:194
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!