2013年7月5日

valid binary search tree

摘要: class Solution {public: bool valid(TreeNode *node, stack& s) { if( node == NULL ) return true; stack left,right; if( !valid(node->left,left) ) return false; if( !left.empty() ) { if( left.top() >= node->val ) {... 阅读全文

posted @ 2013-07-05 21:55 jumping_grass 阅读(159) 评论(0) 推荐(0)

remove nth node from end of list

摘要: class Solution {public: ListNode *removeNthFromEnd(ListNode *head, int n) { // Start typing your C/C++ solution below // DO NOT write int main() function if( head == NULL ) return head; ListNode * root = new ListNode(-1); root->next = head; while(... 阅读全文

posted @ 2013-07-05 19:56 jumping_grass 阅读(115) 评论(0) 推荐(0)

combination sum 2

摘要: class Solution { public: void comb(vector &candidates,int pos,vector >& v,int target) { if( target == 0 ){ v.push_back(v.back()); } for( int i=pos; i target ) { return; } if(... 阅读全文

posted @ 2013-07-05 19:46 jumping_grass 阅读(187) 评论(0) 推荐(0)

combination sum

摘要: class Solution { public: void comb(vector &candidates,int pos,vector >& v,int target) { if( target == 0 ){ v.push_back(v.back()); } for( int i=pos; i target ) { return; } v.back().p... 阅读全文

posted @ 2013-07-05 19:29 jumping_grass 阅读(137) 评论(0) 推荐(0)

put queens

摘要: class Solution {public: vector> v; void putqueen(int k,vector &pos) { //cout tmp( pos.size(),s); for(int i=0;i > solveNQueens(int n) { // Start typing your C/C++ solution below // DO NOT write int main() function v.clear(); if( n== 0 ) return v;... 阅读全文

posted @ 2013-07-05 17:46 jumping_grass 阅读(163) 评论(0) 推荐(0)

rotate image

摘要: class Solution {public: void rotate(vector > &matrix) { // Start typing your C/C++ solution below // DO NOT write int main() function if( matrix.size() == 1 ) return; int start = 0; int n = matrix.size(); int tmp = 0; while( start < n ) { ... 阅读全文

posted @ 2013-07-05 16:28 jumping_grass 阅读(97) 评论(0) 推荐(0)

trap rain water

摘要: 1 class Solution { 2 public: 3 int trap(int A[], int n) { 4 // Start typing your C/C++ solution below 5 // DO NOT write int main() function 6 if( n==0 )return 0; 7 int volum = 0; 8 stack s; 9 s.push(0);10 int t;11 for(int i=1;i= A[... 阅读全文

posted @ 2013-07-05 11:52 jumping_grass 阅读(150) 评论(0) 推荐(0)

导航