1.反转链表LeetCode206Easy
分析:从前往后扫,一个一个扫即可。
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode* reverseList(ListNode* head) { ListNode *new_head=NULL; while(head){ ListNode *next=head->next; head->next=new_head; new_head=head; head=next; } return new_head; }};
2求子集LeetCode78Medium
分析:位运算回溯
class Solution {public: vector> subsets(vector & nums) { vector >result; int number=1<