剑指offer
椎名丶真白
这个作者很懒,什么都没留下…
展开
-
剑指offer63
#include<iostream>#include<map>using namespace std;int f(int *p,int n) { if (p == NULL || n <= 0) return INT_MIN; int min = p[0]; int v = INT_MIN; for (int i = 1; i < n; i++)...原创 2018-05-27 19:58:23 · 158 阅读 · 0 评论 -
剑指offer46
int num=0;void Translation(string s, int n) { if (n == s.length()) { num++; } else if(n<s.length()){ Translation(s, n + 1); if (n<s.length() - 1 && (((s[n] - '0')*10 + s[n + 1]...原创 2018-04-29 10:44:15 · 259 阅读 · 0 评论 -
剑指offer42
#include<iostream>using namespace std;int FindMaxSum(int *num,int len) { if (num == NULL||len<=0) return -1; int max = 0, i = 1,sum = num[0]; while (i<len){ if (sum < num[i]&...原创 2018-04-27 22:01:57 · 176 阅读 · 0 评论 -
剑指offer41
#include<iostream>#include<set>#include<vector>#include<iomanip>#include <functional>//greater,less的模板using namespace std;void MinK(const vector<int> v,int ...原创 2018-04-27 21:02:55 · 131 阅读 · 0 评论 -
剑指offer39
#include<iostream>using namespace std;int MoreHalfNum(int *num,int len){ int x=num[0],count=1; for (int i = 1; i < len; i++) { if (num[i] == x) count--; if (count == 0) { x = num[...原创 2018-04-27 19:49:24 · 91 阅读 · 0 评论 -
剑指offer38
#include<iostream>using namespace std;void Permutation(char* s,char* p) { if (*p=='\0') cout << s << endl; for (char* begin = p; *begin != '\0'; begin++){ swap(*begin,*p); P...原创 2018-04-27 16:52:10 · 172 阅读 · 0 评论 -
剑指offer35
#include<iostream>using namespace std;struct ListNode{ int value; ListNode* next; ListNode* sp;};ListNode* Copy(ListNode* t) { ListNode *k=NULL; ListNode* p = t; while (p != NULL) {...原创 2018-04-26 18:54:16 · 140 阅读 · 0 评论 -
剑指offer58题目二
#include<iostream>#include<algorithm>using namespace std;char* Change(char *c,int num,int n) { int i = 0, j = num - 1; while (i < j) swap(c[i++],c[j--]); i = num - n; j = num - 1...原创 2018-05-16 22:45:07 · 121 阅读 · 0 评论 -
剑指offer58题目一
#include<iostream>#include<algorithm>using namespace std;char* Overturn(char *c,int n) { int i = 0, j = n - 1; while (i<j) swap(c[i++],c[j--]); int p = 0,q = 0; while (c[q]!='\0...原创 2018-05-16 22:29:40 · 124 阅读 · 0 评论 -
剑指offer34
struct TreeNode { TreeNode* left; TreeNode* Right; double value;};void path(TreeNode *t,int sum,int n,vector<TreeNode *> &v) { if (n == sum&&t->left==NULL&&t->Ri...原创 2018-04-25 15:05:38 · 144 阅读 · 0 评论 -
剑指offer27
#include<iostream>using namespace std;struct TreeNode { TreeNode* left; TreeNode* Right; double value;};void Exchange(TreeNode *t) { if (t!=NULL) { swap(t->left,t->Right); E...原创 2018-04-21 11:31:56 · 190 阅读 · 0 评论 -
剑指offer47
#include<iostream>#include<string>using namespace std;int MaxValue(int *v,int m,int n) { if (v == NULL || m <= 0 || n <= 0) return 0; int**max = new int*[m]; for (int i = 0; i...原创 2018-04-29 11:47:34 · 199 阅读 · 0 评论 -
剑指offer48
#include<iostream>#include<string>using namespace std;void longestString(const char* s) { if (s == NULL) return; int i = 0, j = 1, position[26],maxi=i,maxj=i; for (int k = 0; k <...原创 2018-04-29 13:00:28 · 269 阅读 · 0 评论 -
剑指offer50
#include<iostream>#include<string>#include<map>using namespace std;char OneNum(char *s) { map<char, int> m; int i = 0; while(s[i] != '\0') { m[s[i]]++; i++; } i =...原创 2018-04-29 17:07:24 · 134 阅读 · 0 评论 -
剑指offer61
#include<iostream>#include<map>using namespace std;bool f(int *p) { map<int, int> m; int i = 0; while (i<5){ if (m.find(p[i]) != m.end() && p[i] != 0) return fals...原创 2018-05-27 19:37:39 · 129 阅读 · 0 评论 -
剑指offer57题目二
#include<iostream>#include<algorithm>using namespace std;void Print(int b,int t) { if (b % 2) { int i = b / 2; while (i >= 1) { cout << t - i<<" "; i--; } ...原创 2018-05-16 12:40:40 · 153 阅读 · 0 评论 -
剑指offer57题目一
#include<iostream>#include<algorithm>using namespace std;void Find(int data[],int n,int s,int* num1,int* num2) { int i = 0,j=n-1; while (i<j) { if (data[i] + data[j] > s) j...原创 2018-05-16 11:50:45 · 143 阅读 · 0 评论 -
剑指offer56题目二
#include<iostream>#include<algorithm>using namespace std;int Find(int data[],int n) { if (data == NULL||n<=0) exit(0); int a[32]={0}; for (int i = 0; i < n; i++){ int x = da...原创 2018-05-16 11:24:41 · 113 阅读 · 0 评论 -
剑指offer56题目一
#include<iostream>#include<algorithm>using namespace std;void Find(int data[],int n,int* num1,int* num2) { int x=0; for (int i = 0; i < n;i++) { x ^= data[i] ; } int t = 1; w...原创 2018-05-16 10:41:37 · 109 阅读 · 0 评论 -
剑指offer55题目二
#include<iostream>#include<algorithm>using namespace std;struct TreeNode { TreeNode* l; TreeNode* r; int value;};int b = 1;int depth(TreeNode *t) { if (!t) { return 0; } if...原创 2018-05-15 13:04:58 · 111 阅读 · 0 评论 -
剑指offer55题目一
#include<iostream>#include<algorithm>using namespace std;struct TreeNode { TreeNode* l; TreeNode* r; int value;};int depth(TreeNode *t,int h) { if (t == NULL) return h; else re...原创 2018-05-15 12:41:23 · 137 阅读 · 0 评论 -
剑指offer53题目三
#include<iostream>using namespace std;class Solution {public: int Find(int* p,int b, int e) { int i = b, j = e, mid=(e-b)/2+b; if (p[mid] == mid) { return mid; } else if(i<=j)...原创 2018-05-14 23:29:22 · 102 阅读 · 0 评论 -
剑指offer53题目二
#include<iostream>using namespace std;class Solution {public: int Find(int* p,int n) { int i = 0, j = n - 2,mid; while (i<=j){ mid = (j - i) / 2 + i; if (p[mid] > mid) { ...原创 2018-05-14 23:16:11 · 112 阅读 · 0 评论 -
剑指offer53题目一
class Solution {public: int Begin(int *num,int n,int k) { int i = 0, j = n - 1,mid; while (i<=j){ mid = (j - i)/2 + i; if (num[mid] == k) { if (mid > 0 && num[mid - 1] ==...原创 2018-05-14 22:47:33 · 133 阅读 · 0 评论 -
剑指offer52
#include<iostream>using namespace std;struct ListNode { ListNode(int x = 0) { value = x; } ListNode* next; int value;};ListNode* FristCommonNode(ListNode* a,ListNode* b) { ListNode* aa...原创 2018-04-29 17:47:05 · 143 阅读 · 0 评论 -
剑指offer33
#include<iostream>using namespace std;struct TreeNode { TreeNode* left; TreeNode* Right; double value;};int check(char *v,int len) { if (v == NULL||len<=0) return 0; int i; if (le...原创 2018-04-25 14:09:34 · 158 阅读 · 0 评论 -
剑指offer26
#include<iostream>using namespace std;struct TreeNode { TreeNode* left; TreeNode* Right; double value;};bool Equal(TreeNode *a, TreeNode *b) { if (a == NULL || b == NULL) return false;...原创 2018-04-21 11:08:29 · 113 阅读 · 0 评论 -
剑指offer32
#include<iostream>#include<queue>using namespace std;struct TreeNode { TreeNode* left; TreeNode* Right; double value;};void Print(TreeNode *t) { if (t == NULL) return; queue<...原创 2018-04-23 22:14:08 · 131 阅读 · 0 评论 -
剑指offer23
#include<iostream>using namespace std;struct ListNode { int value; ListNode* next;};ListNode* Find(ListNode* head){ ListNode*fast=head->next, *slow=head; while (fast!=slow){ fast ...原创 2018-04-18 18:56:32 · 131 阅读 · 0 评论 -
剑指offer28
#include<iostream>using namespace std;struct TreeNode { TreeNode* left; TreeNode* Right; double value;};bool checkin(TreeNode* a, TreeNode* b) { if (a == b&&b == NULL) return t...原创 2018-04-22 16:13:17 · 86 阅读 · 0 评论 -
剑指offer22
#include<iostream>using namespace std;struct ListNode { int value; ListNode* next;};ListNode* Find(ListNode* head,int n){ ListNode *p=head, *q=head; int num = 0; if (head == NULL||n==...原创 2018-04-18 15:05:21 · 117 阅读 · 0 评论 -
剑指offer21
#include<iostream>using namespace std;bool check(int x) { return (x & 1) == 0;}//判断是否为偶数void moveNum(int *v,int len,bool(*f)(int)) { if (v == NULL || len == 0) return; int *p = v, *...原创 2018-04-17 11:43:54 · 169 阅读 · 0 评论 -
剑指offer20
#include<iostream>using namespace std;class Solution {public: bool checkInt(char **s) { if (**s == '-' || **s == '+') (*s)++; char *p = *s; while (*s!=NULL&&**s>='0'&&a...原创 2018-04-17 10:25:22 · 133 阅读 · 0 评论 -
剑指offer6
#include<iostream>#include<vector>#include<string>#include<stack>using namespace std;struct ListNode{ int nValue; ListNode* pNext;};void Print(ListNode *head) { st...原创 2018-04-03 11:13:48 · 160 阅读 · 0 评论 -
剑指offer5
#include<iostream>#include<vector>#include<string>using namespace std;class Solution {public: void ReplaceBlank(char s[],int length) { if (length == 0) return; int count =...原创 2018-04-03 10:36:21 · 102 阅读 · 0 评论 -
剑指offer4
#include<iostream>#include<vector>using namespace std;class Solution {public: bool Find(int *matrix,int rows,int colums,int number) { int i = 0; int j = colums-1; if (matrix !...原创 2018-04-02 22:08:47 · 110 阅读 · 0 评论 -
剑指offer19
#include<iostream>using namespace std;bool check(char* str, char* pattern,int i,int j) { if (str[i] == '\0'&&pattern[j] == '\0') return true; if (str[i] == '\0'&&pattern[j] ...原创 2018-04-14 22:43:34 · 150 阅读 · 0 评论 -
剑指offer3
#include<iostream>#include<vector>using namespace std;class Solution {public: int duplicate(vector<int> numbers) { int i = 0; while(i < numbers.size()) { if (numbe...原创 2018-04-02 12:48:38 · 116 阅读 · 0 评论 -
剑指offer18
#include<iostream>using namespace std;struct ListNode { int value; ListNode* pnext;};void DeleteNode(ListNode** pListHead,ListNode* pDeleted) { if (!pListHead || !pDeleted) return; if ...原创 2018-04-14 16:49:08 · 191 阅读 · 0 评论 -
剑指offer24
#include<iostream>using namespace std;struct ListNode { int value; ListNode* next;};ListNode* ReverseList(ListNode* head){ if (!head) return NULL; ListNode*p=head, *q=NULL,*h=head->...原创 2018-04-18 20:05:05 · 143 阅读 · 0 评论