1957

无聊蛋疼的1957写的低端博客
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
上一页 1 ··· 11 12 13 14 15 16 17 18 19 ··· 22 下一页

2013年8月26日

摘要: - -最多可以买两次。。。最大收益。。。第一想法,枚举分割线,然后按I那种做法来做,算两边的最大收益。= =时间复杂度O(n^2)其实可以这么想啦..从刚才的枚举分割线的想法,那么我就用两个数组记录从左到右的最大收益,另外一个是从右往左的最大收益.那么还是枚举分割线哒!但是实践复杂度就是O(n)啦.class Solution {public: void calc(vector&data , vector&f){ int minx = 0; int ans = 0; f[0] = 0; for(int i = 1 ; i &data... 阅读全文

posted @ 2013-08-26 14:05 1957 阅读(352) 评论(0) 推荐(0) 编辑

2013年8月25日

摘要: = =就是个模拟题class Solution {public: vector > generate(int numRows) { // Start typing your C/C++ solution below // DO NOT write int main() function vector > ans; vector tmp; if(numRows == 0) return ans; tmp.push_back(1); ans.push_back(tmp); fo... 阅读全文

posted @ 2013-08-25 17:48 1957 阅读(186) 评论(0) 推荐(0) 编辑

摘要: 简单题,一般的dp入门题。只是要求O(n)的空间,目测是想要求数组迭代吧。但是从上往下推就不用额外空间了PS。写了if没写else都是sb,害得我看这个简单代码调试了10分钟class Solution {public: int minimumTotal(vector > &triangle) { // Start typing your C/C++ solution below // DO NOT write int main() function for(int i = 1 ; i < triangle.size() ; i++){ ... 阅读全文

posted @ 2013-08-25 12:52 1957 阅读(297) 评论(0) 推荐(0) 编辑

2013年8月23日

摘要: 判断一个数字是否是回文,但是不能使用额外的空间- -!不知道我定义一个div变量算不算额外空间-,-class Solution {public: bool isPalindrome(int x) { // Start typing your C/C++ solution below // DO NOT write int main() function if(x = 10) div = div * 10; while(x){ if(x / div != x % 10) return false; ... 阅读全文

posted @ 2013-08-23 10:18 1957 阅读(461) 评论(0) 推荐(0) 编辑

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 阅读(138) 评论(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 阅读(158) 评论(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 阅读(2772) 评论(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 阅读(190) 评论(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 阅读(358) 评论(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 阅读(4103) 评论(2) 推荐(0) 编辑

上一页 1 ··· 11 12 13 14 15 16 17 18 19 ··· 22 下一页