上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 25 下一页
摘要: 《剑指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( !... 阅读全文
posted @ 2013-09-14 22:22 冰点猎手 阅读(261) 评论(0) 推荐(0) 编辑
摘要: 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 阅读全文
posted @ 2013-09-14 21:11 冰点猎手 阅读(185) 评论(0) 推荐(0) 编辑
摘要: 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) 阅读全文
posted @ 2013-09-14 17:18 冰点猎手 阅读(300) 评论(0) 推荐(0) 编辑
摘要: 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 =... 阅读全文
posted @ 2013-09-14 16:24 冰点猎手 阅读(192) 评论(0) 推荐(0) 编辑
摘要: 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 阅读全文
posted @ 2013-09-14 11:17 冰点猎手 阅读(152) 评论(0) 推荐(0) 编辑
摘要: 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 阅读全文
posted @ 2013-09-14 10:50 冰点猎手 阅读(196) 评论(0) 推荐(0) 编辑
摘要: Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most two transactions.Note:You may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again).分析: Fi 阅读全文
posted @ 2013-09-13 16:03 冰点猎手 阅读(249) 评论(0) 推荐(0) 编辑
摘要: Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one and sell one share of the stock multiple times). However, you may not engage in multiple transactions 阅读全文
posted @ 2013-09-13 15:56 冰点猎手 阅读(192) 评论(0) 推荐(0) 编辑
摘要: Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), design an algorithm to find the maximum profit. 从右到左扫描,维护一个当前节点右边最低的股价,用当前股价和最低股价的差作为最大收益交易的候选。扫描一遍,即可得 阅读全文
posted @ 2013-09-13 15:53 冰点猎手 阅读(139) 评论(0) 推荐(0) 编辑
摘要: Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.分析: 对于每一列从右到左看成一个直方图,每个直方图计算最大面积的时间复杂度为O(n) 所以总的时间复杂度是O(n2)class Solution {public: int maxArea(vector &m) { int size = m.size(); stack s; int area, maxArea ... 阅读全文
posted @ 2013-09-13 09:57 冰点猎手 阅读(155) 评论(0) 推荐(0) 编辑
上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 25 下一页