上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 20 下一页
摘要: int maxProfit(vector &prices) { // Start typing your C/C++ solution below // DO NOT write int main() function if(prices.empty()) return 0; int buy = prices[0]; int maxprofit = 0; for(int i=1;ibuy) maxprofit += (prices[i]-buy); ... 阅读全文
posted @ 2013-10-08 15:25 summer_zhou 阅读(118) 评论(0) 推荐(0) 编辑
摘要: DP int maxProfit(vector &prices) { // Start typing your C/C++ solution below // DO NOT write int main() function if(prices.empty()) return 0; vector profit1(prices.size(),0); vector profit2(prices.size(),0); int minPrice = prices[0]; ... 阅读全文
posted @ 2013-10-08 15:01 summer_zhou 阅读(131) 评论(0) 推荐(0) 编辑
摘要: 需要跳过不是alnum的字符。 bool isPalindrome(string s) { // Start typing your C/C++ solution below // DO NOT write int main() function if(s.empty()) return true; int i = 0,j = s.size()-1; while(true) { while(i=j) retu... 阅读全文
posted @ 2013-10-08 09:57 summer_zhou 阅读(141) 评论(0) 推荐(0) 编辑
摘要: 回溯 int sumNumbers(TreeNode *root) { // Start typing your C/C++ solution below // DO NOT write int main() function if(!root) return 0; int sum = 0; dfs(root,0,sum); return sum; } void dfs(TreeNode* root,int num, int& sum) { ... 阅读全文
posted @ 2013-10-08 09:46 summer_zhou 阅读(156) 评论(0) 推荐(0) 编辑
摘要: 回溯 vector > pathSum(TreeNode *root, int sum) { // Note: The Solution object is instantiated only once and is reused by each test case. vector> res; if(!root) return res; vector path; dfs(root,sum,path,res); return res; } void ... 阅读全文
posted @ 2013-10-08 09:16 summer_zhou 阅读(139) 评论(0) 推荐(0) 编辑
摘要: DP bool wordBreak(string s, unordered_set &dict) { // Note: The Solution object is instantiated only once and is reused by each test case. //dp if(dict.find(s)!=dict.end()) return true; int n = s.size(); vector> dp(n,vector(n,false)); int i,j,k... 阅读全文
posted @ 2013-10-06 23:22 summer_zhou 阅读(128) 评论(0) 推荐(0) 编辑
摘要: RandomListNode *copyRandomList(RandomListNode *head) { // Note: The Solution object is instantiated only once and is reused by each test case. //three steps//1. 为原链表中每个节点创建一个shallow copy,用next指针指向这个copy节点。//2. 利用原链表的next指针,将新链表的random指针指向正确的节点。//3. 将两个链表分开。 if(!head) ... 阅读全文
posted @ 2013-10-06 22:55 summer_zhou 阅读(164) 评论(0) 推荐(0) 编辑
摘要: Q:Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.Here are few examples.[1,3,5,6], 5 → 2[1,3,5,6], 2 → 1[1,3,5,6], 7 → 4[1,3,5,6], 0 → 0A: 在有序数组中找到等于tar 阅读全文
posted @ 2013-10-06 22:26 summer_zhou 阅读(162) 评论(0) 推荐(0) 编辑
摘要: Given a string containing just the characters'(',')','{','}','['and']', determine if the input string is valid.The brackets must close in the correct order,"()"and"()[]{}"are all valid but"(]"and"([)]"are not.A: 阅读全文
posted @ 2013-10-06 17:20 summer_zhou 阅读(153) 评论(0) 推荐(0) 编辑
摘要: ListNode *swapPairs(ListNode *head) { // Note: The Solution object is instantiated only once and is reused by each test case. ListNode *prev,*cur,*next; if(!head||!head->next) return head; ListNode* newhead,*pprev; prev = head; cur = prev->nex... 阅读全文
posted @ 2013-10-06 14:45 summer_zhou 阅读(125) 评论(0) 推荐(0) 编辑
上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 20 下一页