![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode。。。不会
文章平均质量分 52
john_and_betty
这个作者很懒,什么都没留下…
展开
-
Count and Say
class Solution {public: string countAndSay(int n) { string s="1"; for(int i=1;i<=n-1;i++) { string snext=""; int keynum=0; char key='-'原创 2014-03-10 23:20:47 · 286 阅读 · 0 评论 -
Palindrome Number
class Solution {public: bool isPalindrome(int x) { if(x<0) return false; int a=x,b=x; int te=0; while(a!=0) { te=te*10+a%10;原创 2014-03-27 21:57:38 · 294 阅读 · 0 评论 -
Largest Rectangle in Histogram
>>>>>>class Solution {public: int largestRectangleArea(vector &height) { int maxarea=0; stacks; for(int i=0;i<height.size();i++) { if(s.empty())原创 2014-03-17 12:52:44 · 312 阅读 · 0 评论 -
Word Break II
class Solution {public:vectorres;vectortemp;vector*dp;vector wordBreak(string s,unordered_set&dict){ dp=new vector[s.size()]; for(int i=0;i<s.size();i++) for(int j=i;j<s.size();j++)原创 2014-03-21 14:40:25 · 552 阅读 · 0 评论 -
Palindrome Partitioning
class Solution {public: vector> partition(string s) { vector>res; vectorpath; if(s.size()==0) return res; store(res,path,s); } void store(vector原创 2014-03-20 20:04:06 · 295 阅读 · 0 评论 -
Word Ladder
class Solution {public: int ladderLength(string start, string end, unordered_set &dict) { queue>q; unordered_setvisited; q.push(make_pair(start,1)); visited.insert原创 2014-03-21 15:13:33 · 301 阅读 · 0 评论 -
Insert Interval
class Solution {public: vector insert(vector &intervals, Interval newInterval) { vectorres; for(int i=0;i<intervals.size();i++) { if(intervals[i].end<newInterv原创 2014-03-22 22:03:46 · 346 阅读 · 0 评论 -
Wildcard Matching
class Solution {public: bool isMatch(const char *s, const char *p) { const char *ss=s; const char *star=NULL; while(*s!='\0') { if(*s==*p||*s=原创 2014-03-21 22:50:44 · 299 阅读 · 0 评论 -
Best Time to Buy and Sell Stock III
class Solution {public: int maxProfit(vector &prices) { if(prices.size()<=1) return 0; int left[prices.size()]; int minp=prices[0]; left[0]=0;原创 2014-03-22 20:43:46 · 279 阅读 · 0 评论 -
Unique Binary Search Trees II
class Solution {public: vector generateTrees(int n) { return generate(0,n-1); } vector generate(int begin,int end) { vectorres; if(begin>end) {原创 2014-03-24 20:18:54 · 413 阅读 · 0 评论 -
Convert Sorted Array to Binary Search Tree
智商是硬伤啊,昨天在华为做了一道简单的递归都没写出来,尼玛,现在想想实在是愚蠢至极,还特么想拿华为当垫脚石,递归都不会class Solution {public: TreeNode *sortedArrayToBST(vector &num) { return sorta(num,0,num.size()-1); } TreeNode原创 2014-03-24 18:21:59 · 369 阅读 · 0 评论 -
Convert Sorted List to Binary Search Tree
class Solution {public: TreeNode *sortedListToBST(ListNode *head) { ListNode *p; int count=0; p=head; while(p!=NULL) { count++; p=p原创 2014-03-24 19:17:14 · 271 阅读 · 0 评论 -
Divide Two Integers
class Solution {public: int divide(int dividend, int divisor) { if(dividend==0) return 0; int tag=0; if(dividend>0&&divisor0) tag=1; long l原创 2014-03-25 19:04:18 · 380 阅读 · 0 评论 -
Remove Duplicates from Sorted Array II
class Solution {public: int removeDuplicates(int A[], int n) { if(n<=1) return n; int j=1; int value=A[0]; int count=1; for(int i=1;i<n;i++)原创 2014-03-25 18:18:47 · 269 阅读 · 0 评论 -
Spiral Matrix
今天的几道题都没怎么搞懂。。class Solution {public: vector spiralOrder(vector > &matrix) { vectorans; if(matrix.size()==0) return ans; int x1=0,x2=matrix.size()-1,y1=0,y2=ma原创 2014-03-17 20:01:18 · 378 阅读 · 0 评论 -
Rotate Image
Matrix[i][j]-------->>>>Matrix[j][n - i]每4个元素为一组相互交换。class Solution {public: void rotate(vector > &matrix) { int n=matrix.size()-1; for(int i=0;i<n;i++) fo原创 2014-03-17 18:54:26 · 312 阅读 · 0 评论 -
Decode Ways
class Solution {public: int numDecodings(string s) { if(s.size()==0) return 0; int f[s.size()]; if(s[0]=='0') f[0]=0; else f[0]=1;原创 2014-03-15 14:48:39 · 341 阅读 · 0 评论 -
Median of Two Sorted Arrays
找出两个已排序数组的中间数,还没看懂。。class Solution {public: double findMedianSortedArrays(int A[], int m, int B[], int n) { int total=m+n; if(total%2!=0) return find(A,m,B,n,tota原创 2014-03-10 22:38:20 · 365 阅读 · 0 评论 -
gas station leetcode
class Solution {public: int canCompleteCircuit(vector &gas, vector &cost) { int sum=0,total=0,i,start=0; for(i=0;i<gas.size();i++) { sum=sum+gas[i]-cost[i];原创 2014-03-06 22:56:46 · 407 阅读 · 0 评论 -
Valid Parentheses
需要考虑的比较多,容易错class Solution {public: bool isValid(string s) { if(s.size()==0) return false; if(s.size()%2==1) return false; stackstr; int i=原创 2014-03-11 17:37:57 · 278 阅读 · 0 评论 -
Plus One
class Solution {public: vector plusOne(vector &digits) { vectorres; int num=1; for(int i=digits.size()-1;i>=0;i--) { num=num+digits[i]; res原创 2014-03-11 19:16:45 · 316 阅读 · 0 评论 -
Container With Most Water
没看懂题目,看了这个:http://www.cnblogs.com/codingmylife/archive/2012/09/05/2671548.html大意就是,找出任意两个板之间所夹的最大面积,用两个指针,分别指向首尾,计算面积后,改变较小指针的指向class Solution {public: int maxArea(vector &height) { i原创 2014-03-12 09:24:24 · 299 阅读 · 0 评论 -
Binary Tree Maximum Path Sum
class Solution {public: int maxpath(TreeNode *root,int &maxlocal) { if(root==NULL) return 0; int local=root->val; int left=maxpath(root->left,maxlocal);原创 2014-03-07 14:05:51 · 393 阅读 · 0 评论 -
Valid Number
完全就是照打一遍class Solution {public: bool isNumber(const char *s) { if(s==NULL) return false; while(*s==' ') s++; if(*s=='+'||*s=='-') s+原创 2014-03-14 14:03:03 · 287 阅读 · 0 评论 -
Maximal Rectangle
不会写。。。class Solution {public: int f[1000][1000]; int maximalRectangle(vector > &matrix) { for(int i=0;i<matrix.size();i++) f[i][0]=matrix[i][0]=='1'?1:0; for(in原创 2014-03-14 12:57:12 · 344 阅读 · 0 评论 -
Trapping Rain Water
一个点所能容纳的水由它左侧和右侧的最大高度决定,两次扫描得到最大高度,这个点能容纳的水量是由最大高度里面的最小值减去点的高度决定class Solution {public: int trap(int A[], int n) { if(n<=2) return 0; int leftmax[n]; leftmax[原创 2014-03-14 14:53:40 · 328 阅读 · 0 评论 -
max points on a line
const double INF=1E9;class Solution {public: int maxPoints(vector &points) { if(points.size()==0) return 0; unordered_mapmp; int res=1; for(int i=原创 2014-03-14 21:10:15 · 298 阅读 · 0 评论 -
Symmetric Tree
我居然不会!!傻瓜题目!!!可以细化到,一个根节点下面两个子节点之间的比较class Solution {public: bool isSymmetric(TreeNode *root) { if(root==NULL) return true; return judge(root->left,root->right);原创 2014-03-10 12:57:58 · 497 阅读 · 0 评论 -
Populating Next Right Pointers in Each Node I&II
class Solution {public: void connect(TreeLinkNode *root) { if(!root)return ; if(root->left) root->left->next=root->right; if(root->right) root->rig原创 2014-03-09 14:15:44 · 430 阅读 · 0 评论 -
Construct Binary Tree from Inorder and Postorder Traversal
class Solution {public: TreeNode *buildTree(vector &inorder, vector &postorder) { if(inorder.size()==0) return NULL; return traverse(inorder,0,inorder.size()-1,postorde原创 2014-03-15 13:37:23 · 414 阅读 · 0 评论 -
Sudoku Solver
class Solution {public: void solveSudoku(vector > &board) { solve(board); } bool solve(vector>&board) { for(int i=0;i<9;i++) for(int j=0;j<9;j++)原创 2014-03-26 19:48:48 · 379 阅读 · 0 评论