上一页 1 ··· 9 10 11 12 13

2014年3月7日

Same Tree

摘要: 我觉得和树的遍历很像,想用递归,不过返回值那块我很迷茫,递归使用栈,返回值是返回给上一层的,我怎么才能让递归只返回一个bool值呢,阶乘可以用递归来写,返回值也只有一个,如果我一定这样写的话,我就让返回值做“与”操作,感觉程序写出来很ugly,不管了,小菜鸟先这么写着,之后再参看网上大牛的大作,嘿嘿呃,也许不是吧,递归中return到底是什么样子的呀,写个小程序看看吧: 1 #include 2 3 using namespace std; 4 5 //判断2个数组中元素是否都相等 6 //程序本身没有什么意思,一些条件也没有判断,比如说为空什么的, 7 //我只是想看看递归中retur... 阅读全文

posted @ 2014-03-07 10:33 crane_practice 阅读(187) 评论(0) 推荐(0) 编辑

2014年3月6日

Remove Duplicates from Sorted List

摘要: /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode *deleteDuplicates(ListNode *head) { if(head) { ListNode *p,*q; p=head; ... 阅读全文

posted @ 2014-03-06 21:21 crane_practice 阅读(112) 评论(0) 推荐(0) 编辑

Length of Last Word

摘要: 1 class Solution { 2 public: 3 int lengthOfLastWord(const char *s) { 4 int length=0; 5 int i=0; 6 int n=0;//存储遇到空格之前的word的长度 7 if(s!=NULL) 8 { 9 10 while(s[i]!='\0')11 {12 while(s[i]!=' ')13 ... 阅读全文

posted @ 2014-03-06 19:31 crane_practice 阅读(217) 评论(0) 推荐(0) 编辑

2014年3月5日

Remove Element

摘要: 源码: 1 class Solution { 2 public: 3 int removeElement(int A[], int n, int elem) { 4 sort(A,A+n); 5 int i,j; 6 i=0; 7 j=n-1; 8 while(i<=j) 9 {10 if(A[i]!=elem)11 {12 i++;13 }14 else15 ... 阅读全文

posted @ 2014-03-05 18:49 crane_practice 阅读(153) 评论(0) 推荐(0) 编辑

Remove Duplicates from Sorted Array

摘要: 我的思路:如果一个一个比较的话就是太野蛮的写法了,可以先排序在处理关于排序函数参看:http://www.cnblogs.com/ForeverJoker/archive/2013/05/25/qsort-sort.html(在本题中题目上说了Given a sorted array,人家已经排好序啦``````)刚开始写的,结果:Time Limit Exceeded 1 class Solution { 2 public: 3 int removeDuplicates(int A[], int n) { 4 if(n1,2,2,3——>1,2,3,3但是,如果是1,... 阅读全文

posted @ 2014-03-05 18:38 crane_practice 阅读(209) 评论(0) 推荐(0) 编辑

上一页 1 ··· 9 10 11 12 13

导航