1957

无聊蛋疼的1957写的低端博客
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

2013年8月22日

摘要: 感觉比I还水能买卖多次...问最大收益...class Solution {public: int maxProfit(vector &prices) { // Start typing your C/C++ solution below // DO NOT write int main() function int ans = 0; for(int i = 1 ; i 0) ans += prices[i] - prices[i-1]; return ans; }}; 阅读全文

posted @ 2013-08-22 20:48 1957 阅读(142) 评论(0) 推荐(0)

摘要: 水题,就是找aj - ai 最大 j > i一般就是o(n^2),不过从左到右扫一遍就好了复杂度O(n)只需要记录最小的就ok.class Solution {public: int maxProfit(vector &prices) { // Start typing your C/C++ solution below // DO NOT write int main() function int minx = 0; int ans = 0; for(int i = 0 ; i ans) ans = prices[... 阅读全文

posted @ 2013-08-22 20:45 1957 阅读(161) 评论(0) 推荐(0)

摘要: 二叉树,找出任意一点到另一点的路径,使得和最大.开始sb看错题了...其实嘛...我们递归的来看...如果只是一个节点,那么当然就是这个节点的值了.如果这个作为root,那么最长路应该就是..F(left) + F(right) + val...当然如果left,或者right left); int right = scanT(root -> right); int val = root -> val; if(left > 0) val += left; if(right > 0) val += right; if(val ... 阅读全文

posted @ 2013-08-22 20:11 1957 阅读(2785) 评论(1) 推荐(0)

摘要: 看着比较有意思的水题就是判断一个树是否是对称的. 1 / \ 2 2 / \ / \3 4 4 3这个是可以的。。。 1 / \ 2 2 \ \ 3 3这样是不行的。那么我们就从两边开始递归比较就好啦。/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} ... 阅读全文

posted @ 2013-08-22 16:41 1957 阅读(195) 评论(0) 推荐(0)

摘要: 一次只允许变动一个字符,然后得到目标字符串最少步数.我们把每个合法字符看成一个点,之间的变化看成边,那么就是个图,就是球start到end的最短路.用BFS就可以了...class Solution {public: int ladderLength(string start, string end, unordered_set &dict) { // Start typing your C/C++ solution below // DO NOT write int main() function if(start == end) return... 阅读全文

posted @ 2013-08-22 14:32 1957 阅读(365) 评论(0) 推荐(0)

摘要: 最近经常闲的无聊,于是就做做leetcode的题了,目测好像都不是很难.不过呢,闲的无聊还是记录下某些做了的题.Given an unsorted array of integers, find the length of the longest consecutive elements seque... 阅读全文

posted @ 2013-08-22 10:13 1957 阅读(4111) 评论(2) 推荐(0)