今天是纠结要不要新买手机的一天QAQ想了想还是算了吧,等自己赚钱买,加油
Num 70 爬楼梯 Climbing Stairs

class Solution { public: int climbStairs(int n) { int a[10000]; a[1]=1; a[2]=2; for(int i=3;i<=n;i++) a[i]=a[i-1]+a[i-2]; return a[n]; } };
Num 83 删除链表中的重复元素 Remove Duplicates from Sorted List
注意一下这个,刚开始为了简化代码写错了。在相同的时候,pre是不需要改变的

/** * 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==NULL) return head; int now=head->val; ListNode*temp=new ListNode(0); ListNode*pre=new ListNode(0); pre=head; temp=head->next; while(temp!=NULL) { if(temp->val==now) { pre->next=temp->next; } else pre=temp; now=temp->val; temp=temp->next; } return head; } };