![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
刷题之剑指offer
编码熟手
这个作者很懒,什么都没留下…
展开
-
剑指offer 替换空格
// 替换空格.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include "string.h"/*请实现一个函数,将一个字符串中的空格替换成“%20”。例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy。fun调用者保证缓冲足够大*/void fun(c原创 2018-01-31 13:57:35 · 101 阅读 · 0 评论 -
二叉树的镜像
// .cpp : //#include "stdafx.h"#include <queue>using namespace std;typedef struct binary_tree{ int val; binary_tree* left; binary_tree* right;}BINARY_TREE;BINARY_TREE* tree = NULL;void create_...原创 2018-03-14 15:05:55 · 115 阅读 · 0 评论 -
树的子结构
// .cpp : //#include "stdafx.h"#include <queue>using namespace std;typedef struct binary_tree{ int val; binary_tree* left; binary_tree* right;}BINARY_TREE;BINARY_TREE* tree = NULL;BINARY_TREE*...原创 2018-03-13 17:03:22 · 87 阅读 · 0 评论 -
二叉树中和为某个值得路径
// .cpp : //#include "stdafx.h"#include <queue>using namespace std;typedef struct binary_tree{ int val; binary_tree* left; binary_tree* right;}BINARY_TREE;BINARY_TREE* tree = NULL;void create_...原创 2018-03-23 10:46:15 · 118 阅读 · 0 评论 -
包含min函数的栈
// min.cpp : //#include "stdafx.h"#include <stack>using namespace std;class simplestack{public: stack<int> s; stack<int> mins;public: void push(int v); void pop(); int min();};void...原创 2018-03-15 15:14:07 · 96 阅读 · 0 评论 -
链表倒数第k个节点
// k.cpp : //#include "stdafx.h"typedef struct _node{ int v; _node* pNext;}NODE;NODE* head = NULL;void init_list(){ NODE* pCur; int i = 0; while( i < 100) { if (head == NULL) { head = new NOD...原创 2018-03-01 10:19:49 · 110 阅读 · 0 评论 -
顺时针打印矩阵
// .cpp : //#include "stdafx.h"int a[4][4]={ {1,2,3,4}, {5,6,7,8}, {9,10,11,12}, {13,14,15,16}};void print(int hang, int lie){ int i = 0; int j = 0; int start_x = 0; int start_y = 0; while (i < h...原创 2018-03-15 10:52:34 · 81 阅读 · 0 评论 -
调整数组顺序使奇数位于偶数前
// jishu_before_oushu.cpp : //#include "stdafx.h"#if 0void fun(int* a, int len){ int head = 0; int tail = len - 1; for (int j = 0;j<len/2;j++) { for(int i = 0; i<len; i++) { if ( (a[i] &am...原创 2018-02-28 15:01:59 · 79 阅读 · 0 评论 -
二进制中1的个数
#include "stdafx.h"#include "stdlib.h"void fn(int v){ int val = v; int cnt = 0; while(val > 0) { int t = (val & 0x1); val >>= 1; if (t == 1) cnt++; } char s[33]; itoa(v, s, 2); pri...原创 2018-02-15 09:56:01 · 97 阅读 · 0 评论 -
剑指offer-斐波那契数列
// Fibonacci.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"int Fibonacci(int v){if ( 0 >= v){return 0;}else if (1 == v){return 1;}else{return Fibonacci(v-1) + Fi原创 2018-02-05 13:50:11 · 107 阅读 · 0 评论 -
栈的压入弹出序列
#include "stdafx.h"#include #include using namespace std;/*j=0for i = 0 is.push(stack_in[i])while s.top == stack_out[j] && !s.emptys.popj++endwhileendfor*/原创 2017-11-10 21:01:42 · 136 阅读 · 0 评论 -
剑指offer-用两个栈实现队列
// twostackqueue.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include using namespace std;class myqueue{public:stack s1;stack s2;public:void push(int v);int front();void原创 2018-02-05 13:30:38 · 88 阅读 · 0 评论 -
剑指offer 反向打印链表
// printlistreverse.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include using namespace std;typedef struct node{int val;node* pNext;}NODE;NODE* gpstHead = NULL;原创 2018-02-01 14:13:30 · 101 阅读 · 0 评论 -
字符串的全排列
// .cpp : //#include "stdafx.h"#include "string.h"void fun(char* pstr, int len){ char* ptmp = new char[len+1]; printf("%s\n\n", pstr); for(int i=0;i<len; i++) { strcpy(ptmp, pstr); for(int j=i+...原创 2018-04-18 21:44:21 · 107 阅读 · 0 评论