摘要: 开始考虑排列组合方法,发现自己实现的求组合函数C(m,n)过大数据时有溢出,换了思路。 1 int climbStairs(int n) { 2 // Start typing your C/C++ solution below 3 // DO NOT write int main() function 4 int* res=new int[n]; 5 res[0]=1; 6 res[1]=2; 7 for(int i =2; i<n;i++){ 8 res[i] = res... 阅读全文
posted @ 2012-09-11 23:49 alex.wu 阅读(331) 评论(0) 推荐(0)
摘要: 1 ListNode *addTwoNumbers(ListNode *l1, ListNode *l2) { 2 // Start typing your C/C++ solution below 3 // DO NOT write int main() function 4 ListNode* l3 = new ListNode(0); 5 ListNode* res = l3; 6 int a,b; 7 int flag=0; 8 int num; 9 whi... 阅读全文
posted @ 2012-09-10 21:48 alex.wu 阅读(405) 评论(0) 推荐(0)
摘要: 1 int lengthOfLastWord(const char *s) { 2 // Start typing your C/C++ solution below 3 // DO NOT write int main() function 4 int res=0,tmp=0; 5 while(*s !='\0'){ 6 if(*s==' '){ 7 tmp= (res?res:tmp); 8 res = 0; 9 ... 阅读全文
posted @ 2012-09-10 21:46 alex.wu 阅读(88) 评论(0) 推荐(0)
摘要: 1 int jump(int A[], int n) { 2 // Start typing your C/C++ solution below 3 // DO NOT write int main() function 4 int count = 0; 5 int end = n-1; 6 while(end){ 7 for(int i = 0; i < end; i++){ 8 if((A[i]+i)>=end){ 9 ... 阅读全文
posted @ 2012-09-10 21:44 alex.wu 阅读(179) 评论(0) 推荐(0)
摘要: 1 bool canJump(int A[], int n) { 2 // Start typing your C/C++ solution below 3 // DO NOT write int main() function 4 if(n <= 1) 5 return true; 6 int target = 0; 7 for(int i = 0; i < n; i++){ 8 if(i+A[i] > target) 9 targ... 阅读全文
posted @ 2012-09-10 21:36 alex.wu 阅读(234) 评论(0) 推荐(0)