zoukankan      html  css  js  c++  java
  • 第1组

    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;
        }
    };
    View Code

    2求子集LeetCode78Medium

    分析:位运算回溯

    class Solution {
    public:
        vector<vector<int>> subsets(vector<int>& nums) {
            vector<vector<int>>result;
            int number=1<<nums.size();
            for(int i=0;i<number;i++){
                vector<int> temp;
                for(int j=0;j<nums.size();j++){
                    if(i&1<<j){
                        temp.push_back(nums[j]);
                    }
                    
                }
                result.push_back(temp);
            }
            return result;
        }
    };
    View Code
  • 相关阅读:
    团队冲刺第八天
    团队冲刺第七天
    团队冲刺第六天
    团队冲刺第五天
    找水王
    团队冲刺第四天
    团队冲刺第三天
    团队冲刺第二天
    团队冲刺第一天
    spring冲刺计划
  • 原文地址:https://www.cnblogs.com/zfc888/p/10544434.html
Copyright © 2011-2022 走看看