import java.io.File;public class ExFile{ public void ff(String s){ try{ File fl=new File(s); fl.createNewFile(); String[] a=f...
分类:
其他好文 时间:
2015-07-10 23:34:11
阅读次数:
129
Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.思路:递归法判断
假设两棵树根结点为...
分类:
其他好文 时间:
2015-06-11 19:22:38
阅读次数:
87
//左旋转字符串abcdefgh->cdefghab//循环递归法
#include
#include
using namespace std;
void runstring(char *str,int n)
{
int i = 0;
int j = i+n;
int len = strlen(str);
char *p =...
分类:
编程语言 时间:
2015-05-30 21:13:50
阅读次数:
194
四、普通选择性组合排列对于搜索的深度非常深或深度不固定的情况,则无法用枚举的方法来设置循环嵌套的层数,这时能够考虑用递归法来完毕搜索任务。递归是一种经常使用算法,它是搜索的还有一种实现方式。假设在算法设计中採用一个函数或过程直接或间接地调用它自身来解决这个问题的方法,则称该方法为递归算法。递归算法必...
分类:
其他好文 时间:
2015-05-13 12:34:50
阅读次数:
90
#include
int nk(int n,int k)
{
if (k == 0)
return 1;
else
return n * nk(n, k - 1);
}
int main()
{
int ret = nk(3,4);
printf("%d\n", ret);
return 0;
}
测试用例为3的4次方,结果是81。
例子较简单,是对递归的简单练习,...
分类:
其他好文 时间:
2015-05-11 14:46:23
阅读次数:
99
//Data为要查找的数组,x为待查找数据值,beg为查找范围起始,last为查找范围终止//非递归法int BiSearch(int data[], const int x, int beg, int last){ int mid;//中间位置 if (beg > last) { return ....
分类:
编程语言 时间:
2015-04-22 17:43:59
阅读次数:
121
题目:用递归法把一个整数转换成字符串输出。比较下面两种方法的不同: putchar(n%10+'0')的位置不同,造成输出结果的不同。方法一: 1 #include 2 void convert(int n) 3 { 4 int i; 5 if((i=n/10)!=0) 6 convert(i).....
分类:
编程语言 时间:
2015-04-20 22:31:24
阅读次数:
234
problem:
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).
For example, this binary tree is symmetric:
1
/ 2 2
/ \ / 3 4 4 ...
分类:
其他好文 时间:
2015-04-20 11:16:24
阅读次数:
209
题目地址:https://leetcode.com/problems/permutations/题目分析:很明显可以使用递归,先将起始位置与后面的每个数字交换位置,然后将起始位置往后移以为,以该起始位置为起点求排列,依次类推即可使用递归法。题目解答:import java.util.ArrayLis...
分类:
其他好文 时间:
2015-04-15 13:24:58
阅读次数:
103
第一种:用递归法(时间复杂度是n的指数级别) #includeint fun(int x){ if(x==1||x==2) return 1; return (fun(x-1)%10007 + fun(x-2)%10007);} int main(){ int n;...
分类:
其他好文 时间:
2015-04-02 01:07:00
阅读次数:
142