
算法
a819721810
这个作者很懒,什么都没留下…
展开
-
全排列算法
public class MyAllSortTest1 { //private static int m=4; public static void Allsort(int a[],int k,int m) { if (k==m) { for (int i = 0; i <= m; i++) { Sys原创 2015-04-07 23:53:34 · 389 阅读 · 0 评论 -
最长回文子串优化
import java.util.Scanner;public class TheLengthPalindromicNumber1 { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); while (原创 2015-04-26 17:47:57 · 472 阅读 · 0 评论 -
same-tree
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./** * Definition原创 2015-05-13 19:45:19 · 562 阅读 · 0 评论 -
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 binary tree * stru原创 2015-05-13 19:32:36 · 761 阅读 · 0 评论 -
查找数组里面的数
有一个int型数组,每两个相邻的数之间的差值不是1就是-1.现在给定一个数,要求查找这个数在数组中的位置。 其实思想就是跳跃查找,因为你知道了一个数,那么它第二个数最多相差1,第三个数最多相差2,而可以用目标数减去这个数来排除一些多余的查找,比如你要的数是10,第一个数是2,那么它前7个数无论如何都达不到10,只有在第8个数才有可能,所以可以直接判断第8个数。 下面是别人的代码借用一下思想大概就原创 2015-05-12 01:34:58 · 970 阅读 · 0 评论 -
用顺序栈判断是不是回文串(C++)
/*typedef struct l{ char data[250]; int top;}stack;void stackinit(stack &w){ w.top=-1;}void stackcreat(stack &w,char ch[]){ char *h; h=ch; cout<<"栈中字符:"<<endl; while(*h!='#') {转载 2015-05-03 11:40:28 · 2888 阅读 · 0 评论 -
顺序栈来判断回文串
#include<stdio.h>#include<string>#include<iostream>using namespace std;#define StackSize 100typedef char DataType;typedef struct{ DataType data[StackSize]; int top;}SeqStack;/*void Int(S原创 2015-05-03 11:39:10 · 2461 阅读 · 0 评论 -
用线性表来解决约瑟夫环问题(C语言)
#include<stdio.h>#include<stdlib.h>#define OK 1;#define ERROR 0;typedef int Status;typedef int Elemtype;typedef struct Cnode{ Elemtype data; struct Cnode *next;}CNode;CNode *joseph;Sta原创 2015-05-03 16:33:05 · 5231 阅读 · 0 评论 -
懂二进制
世界上有10种人,一种懂二进制,一种不懂。那么你知道两个int32整数m和n的二进制表达,有多少个位(bit)不同么? 输入例子: 1999 2299输出例子: 7class Solution {public: /** * 获得两个整形二进制表达位数不同的数量 * * @param m 整数m * @param n 整数n * @原创 2015-04-25 00:18:49 · 1262 阅读 · 0 评论 -
链表操作集合
#include<stdio.h>#include<stdlib.h>typedef int ElemType;typedef struct Node{ ElemType data;struct Node *next;}Node,LinkList;void Insert(LinkList *L,LinkList *p);void Build(LinkList *L){//建立一个空原创 2015-04-15 09:31:33 · 819 阅读 · 0 评论 -
用链表实现一个简单的学生操作管理系统C语言版
#include <stdio.h>#include <math.h>#include <string.h>#include <malloc.h>#include <stdlib.h>#define format "%d\n%s\n%f\n%f\n%f\n"#define len sizeof(stu)typedef struct student{ long num;原创 2015-04-12 18:55:35 · 7680 阅读 · 0 评论 -
未排序数组中累加和为给定值的最长子数组
例如给出 数组 1 1 1 2 1 1(数字可正可负可0),要求定值为3 则子数组应该[1,1,1],输出长度为3#include<iostream>#include<algorithm>#include<map>using namespace std;int max(int a, int b){ if (a > b) return a; return b;}int m原创 2016-04-05 09:56:19 · 813 阅读 · 1 评论