摘要:
《剑指offer 面试题22 》模拟题,模拟判断一个弹出序列是否可能是一个压栈序列的弹出序列bool valid(vector pushS, vector popS){ assert(pushS.size() == popS.size()); int len = pushS.size(); if(len == 0) return true; stack mys; int cur = 0; for(int i = 0; i < len ; ++i) { if(pushS[i] == popS[cur]){ cur++; continue; }else if( !... 阅读全文
摘要:
struct Tree(){ int val; Tree *left, *right; Tree(int a): val(a), left(NULL), right(NULL){}}bool mirrorTree(Tree *root){ if(root == NULL || (root->left== NULL && root->right == NULL)) return NULL ; Tree *tp = root->left; root->left = root->right; root->right = tp; if(root-&g 阅读全文
摘要:
struct Tree(){ int val; Tree *left, *right; Tree(int a): val(a), left(NULL), right(NULL){}}bool hasSubTree(Tree *root1, Tree * root2){ if(root2 == NULL) return true; if(root1 == NULL) return false; bool result = false; if(root1->val == root2->val) result = isSubTree(root1, root2); if(!result) 阅读全文
摘要:
struct ListNode{ int val_; ListNode* next; ListNode(int val): val_(val),next(NULL){}};//非递归ListNode *reverse(ListNode *head){ if(head == NULL) return NULL; ListNode* vir = new ListNode(0); vir->next = NULL; ListNode *p = head; while(p != NULL)){ ListNode *q = p->next; p->next =... 阅读全文
摘要:
void ReorderOddEven(int data[], int n){ if(data == NULL || n < 2) return; int left = 0; int right = n-1; while(left < right) { while(left < right && data[left]&0x01 == 1) ++left; while(left < right && data[right]^0x01 == 0) -- right; if(left < right){ int temp = da 阅读全文
摘要:
struct Node { int val; Node * next;};void deleteNode(Node ** head, Node * target){ assert(head != NULL && *head != NULL && target != NULL); //头结点的判断 if(*head == target) { *head = target->next; delete target; } //尾节点的判断 if(target->next == NULL){ Node *p = *head; while(*p ->ne 阅读全文