1957

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

2014年1月8日

摘要: = =每行放一起,就是一个一维的数组,而且是递增的。。那用二分就好啦。。class Solution {public: pair toXY(int i , int row , int col){ int x = i / col; int y = i % col; return make_pair(x,y); } int getEle(const vector > &matrix , int i){ pair xy = toXY(i , matrix.size() , matrix.front().size... 阅读全文

posted @ 2014-01-08 23:27 1957 阅读(125) 评论(0) 推荐(0)

摘要: 就是做个扫描,能匹配的算下多长,如果不能匹配.就继续从后开始.class Solution {public: int longestValidParentheses(string s) { stack st; int last = -1; int maxlen = 0; for(int i = 0 ; i < s.size() ; i++) { if(s[i] == '(') st.push(i); else{ if(st.empty()){ ... 阅读全文

posted @ 2014-01-08 21:36 1957 阅读(421) 评论(0) 推荐(0)

摘要: 下一排列TAT从右往左找到第一个非增的位置,也就是找到最右递减的开始位置的前一个。定位这个。然后又从右往左找比这个数大的。。。交换着两个数。。然后reverse之前的递减序列。。。因为递减序列就木有next permutation了。。所以找到最右的递减序列那么前面那个肯定是要用比他大的代替啦,再反转递减序列,就是next permutation了class Solution {public: void nextPermutation(vector &num) { int end = num.size() - 1; int povit = end; ... 阅读全文

posted @ 2014-01-08 20:50 1957 阅读(1901) 评论(0) 推荐(0)

摘要: 用hash暴力。。。感觉是刚好过吧。。开始里面多查了两次,就是TLEclass Solution {public: vector findSubstring(string S, vector &L) { int wordLen = L.front().size(); ... 阅读全文

posted @ 2014-01-08 17:30 1957 阅读(167) 评论(0) 推荐(0)

摘要: 左子树的任意节点的值都比root小右子树的任意节点的值都比root大TAT怎么做。。。递归的时候设置个上下界就好了。。。左子树,更新上届右子树,更新下界/** * Definition for binary tree * struct TreeNode { * int val; * ... 阅读全文

posted @ 2014-01-08 16:14 1957 阅读(127) 评论(0) 推荐(0)

摘要: = =简单题...尝试考虑了各种情况.../** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode *reverse(ListNode* start){ ListNode* prev = nullptr; ListNode* now = start; ... 阅读全文

posted @ 2014-01-08 09:17 1957 阅读(584) 评论(0) 推荐(0)