上一页 1 ··· 6 7 8 9 10 11 12 13 14 ··· 16 下一页
摘要: class Solution {public: bool isBalanced(TreeNode *root) { if(root==NULL)return true; int left=depth(root->left); int right=depth(root->right); if(abs(left-right)>1)return false; return isBalanced(root->left)&&isBalanced(root->right); } int depth(Tre... 阅读全文
posted @ 2013-04-16 23:53 代码改变未来 阅读(131) 评论(0) 推荐(0) 编辑
摘要: class Solution {public: string addBinary(string a, string b) { reverse(a.begin(),a.end()); reverse(b.begin(),b.end()); string a1,a2; if(a.length()>=b.length()) { a1=a; a2=b; } else { a1=b; a2=a; ... 阅读全文
posted @ 2013-04-16 21:50 代码改变未来 阅读(164) 评论(0) 推荐(0) 编辑
摘要: 3 suma+b+c=0class Solution {public: vector > threeSum(vector &num) { vector >v; vectorv1; sort(num.begin(),num.end()); for(int i=0;i0)break; for(int a=i+1,b=num.size()-1;a0){b--;} } } return v; }};3 sum clos... 阅读全文
posted @ 2013-04-13 14:37 代码改变未来 阅读(215) 评论(0) 推荐(0) 编辑
摘要: Number114 最小二叉树深度class Solution {public: int minDepth(TreeNode *root) { int depth=0; if(root==NULL)return 0; int left=minDepth(root->left); int right=minDepth(root->right); if(root->left==NULL&&root->right!=NULL) { depth=right+1; } ... 阅读全文
posted @ 2013-04-11 20:43 代码改变未来 阅读(172) 评论(0) 推荐(0) 编辑
摘要: 组合:#include "stdafx.h"#include<iostream>using namespace std;void print(int n,int *A,int cur,int *B){ if(cur==n) { for(int i=0;i<cur;i++) { if(B[i]) { printf("%d",A[i]); } } printf("\n"); return; } B[cur]=1; print(n,A,cur+1,B); B[cur]=0; print(n,A,cur+1,B);}int 阅读全文
posted @ 2013-03-07 14:23 代码改变未来 阅读(155) 评论(0) 推荐(0) 编辑
摘要: 在到处都是牛人的地方,作为一名屌丝,压力不是一般的大。本科混迹于屌丝学校的与计算机毫不相关的专业,后经跨专业考研来到现在的学院。当初复试后找导师屡屡碰壁,最后一个不是很学术也不是很工程的实验室的一名老师收下了我,身边的全是来自于985的本科生。。。研一一年课程勉强混过了75分,全实验室垫底。刚开始的一门课程要做一个项目,5个人一组,结果我所在的组的5个人都不是计算机和软件背景(被其他人抛弃了),另外3人对编程毫无兴趣,于是我和另外一位同学挑起了任务。对于我这种没有任何JAVA基础的人来说,天天捧着Javaweb的书,啃着SSH真痛苦。最后做的东西被老师说是大二本科生的水平。。。给了个最低分。吃 阅读全文
posted @ 2013-01-30 23:20 代码改变未来 阅读(221) 评论(0) 推荐(0) 编辑
摘要: struct BinaryTreeNode{ int value; BinaryTreeNode *left,*right;};bool doestree1havetree2(BinaryTreeNode *root1,BinaryTreeNode *root2);bool hassubtree(BinaryTreeNode *root1,BinaryTreeNode *root2){ bool result=false; if(root1!=NULL&&root2!=NULL) { if(root1->value==root2->value) { result=d 阅读全文
posted @ 2013-01-09 19:55 代码改变未来 阅读(569) 评论(0) 推荐(0) 编辑
摘要: 面试题15:倒数第k个结点。(链表不带头结点)。设置两个指针,一个从头结点开始,走k-1步时另外一个从头开始与该指针同步知道第一个指针到达末尾。ListNode * FindKthToTail(ListNode *pListHead,unsigned int k){ if(pListHead==NULL||k==0) { return NULL; } ListNode *pAhead=pListHead; ListNode *pBehind=NULL; for(int i=0;i<k-1;i++) { if(pAhead->next!=NULL) { pAhead=pAhead-& 阅读全文
posted @ 2013-01-06 19:46 代码改变未来 阅读(255) 评论(0) 推荐(0) 编辑
摘要: 面试题见剑指offer:struct ListNode { int value; ListNode *next; }; void DeleteNode(ListNode **pListHead,ListNode * pToBeDeleted){ if(!pListHead||!pToBeDeleted) return; if(pToBeDeleted->next) { ListNode *pNext=pToBeDeleted->next; pToBeDeleted->value=pNext->value; pToBeDeleted->next=pNext-> 阅读全文
posted @ 2013-01-04 18:54 代码改变未来 阅读(220) 评论(0) 推荐(0) 编辑
摘要: 直接贴代码:#include<iostream>using namespace std;int minInorder(int numbers[],int index1,int index2);int min(int numbers[],int length){ if(length<=0) throw new std::exception("Invalid Input"); int index1=0; int index2=length-1; int mid=index1; while(numbers[index1]>=numbers[index2]) 阅读全文
posted @ 2013-01-03 18:58 代码改变未来 阅读(236) 评论(0) 推荐(0) 编辑
上一页 1 ··· 6 7 8 9 10 11 12 13 14 ··· 16 下一页