自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

Sunburst的专栏

心通了,一切皆有可能

  • 博客(17)
  • 收藏
  • 关注

原创 从上往下打印二叉树

题目描述从上往下打印出二叉树的每个节点,同层节点从左至右打印。/*struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) { }};*/c

2015-05-22 19:18:44 644

原创 用两个栈实现队列

题目描述用两个栈来实现一个队列,完成队列的Push和Pop操作。 队列中的元素为int类型。class Solution{public: void push(int node) { stack1.push(node); } int pop() { if(stack2.empty()) {//第二个栈为空时 while(!stack1.empty()) {

2015-05-18 13:05:52 521

原创 用++操作符完成其它操作符的转换

在只容许使用++操作符的情况下,请完成下面代码,实现减法、乘法和除法。注意:假设操作数全为正整数,并且可以不考虑性能,不能使用–,*,/等操作符。 a). 乘法: int multi(int opl,int op2){//op1*op2} b). 减法: intsub(int op1,int op2){//op1-op2} c). 除法: int div(int op1,int op2)

2015-05-18 06:43:57 978 1

原创 链表建立多项式

#include<stdio.h>#include<stdlib.h>typedef struct Node{ int xishu; int zhishu; struct Node *next;}NoDe;void Build(NoDe *L){ NoDe *p,*q; int a,b; //p=(NoDe*)malloc(sizeof(N

2015-05-14 17:33:17 1151

原创 亲密数

#include <stdio.h> #include <stdlib.h> int qingmiaoduishu(int n){ int i,sum; sum=1;for(i=2;i<=n/2;i++) if (n%i==0) sum+=i; return sum;}void main(){ int a,b,c; for (a=

2015-05-14 11:20:02 757 1

原创 十进制转化为其他进制(C语言)

#include<stdio.h>int a[1000];int k=0;void change(int x,int r){ while (x) { a[k++]=x%r; x=x/r; }}int main(){ int x,r,i; printf("输入一个十进制数:\n"); scanf("%d",&

2015-05-14 11:05:15 3530

原创 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, where in

2015-05-14 05:04:01 502

原创 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 542

原创 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 735

原创 single-number

Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra

2015-05-13 19:22:45 470

原创 查找数组里面的数

有一个int型数组,每两个相邻的数之间的差值不是1就是-1.现在给定一个数,要求查找这个数在数组中的位置。 其实思想就是跳跃查找,因为你知道了一个数,那么它第二个数最多相差1,第三个数最多相差2,而可以用目标数减去这个数来排除一些多余的查找,比如你要的数是10,第一个数是2,那么它前7个数无论如何都达不到10,只有在第8个数才有可能,所以可以直接判断第8个数。 下面是别人的代码借用一下思想大概就

2015-05-12 01:34:58 940

原创 笨小猴

笨小猴的词汇量很小,所以每次做英语选择题的时候都很头疼。但是他找到了一种方法,经试验证明,用这种方法去选择选项的时候选对的几率非常大! 这种方法的具体描述如下:假设maxn是单词中出现次数最多的字母的出现次数,minn是单词中出现次数最少的字母的出现次数,如果maxn-minn是一个质数,那么笨小猴就认为这是个Lucky Word,这样的单词很可能就是正确的答案。 输入 Input 只有一行

2015-05-10 11:05:22 1699

原创 从尾到头打印链表

题目描述输入一个链表,从尾到头打印链表每个节点的值。返回新链表的头结点。/***  struct ListNode {*       int val;*       struct ListNode *next;*       ListNode(int x) :*             val(x), next(NULL) {*       }*  };*/ class Solu

2015-05-07 21:25:15 603

原创 用线性表来解决约瑟夫环问题(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 5154

转载 用顺序栈判断是不是回文串(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 2859

原创 顺序栈来判断回文串

#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 2428

原创 KMP(二)

#include <iostream>#include <cstring>#include <cstdio>using namespace std;int main(){ char a[10050],s[1000007]; int c;scanf("%d",&c); while(c--) { scanf("%s%s",a,s);

2015-05-01 10:30:51 538

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除