头像

ஐ_4

桂林电子科技大学




在线 


最近来访(20)
用户头像
._983
用户头像
Domet
用户头像
77777777777
用户头像
垫底抽風
用户头像
Q_83


ஐ_4
21分钟前
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    void deleteNode(ListNode* node) {
        node->val = node->next->val;
        node->next = node->next->next;
    }
};


活动打卡代码 AcWing 35. 反转链表

ஐ_4
43分钟前
/**
 * 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* cur = NULL;
        while(head)
        {
            ListNode* tem = head->next;
            head->next = cur;
            cur = head;
            head = tem;

        }

        return cur;


    }
};


活动打卡代码 AcWing 78. 左旋转字符串

ஐ_4
1小时前
class Solution {
public:
    string leftRotateString(string str, int n) {
        return str.substr(n) + str.substr(0,n);
    }
};



ஐ_4
1小时前
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode* merge(ListNode* l1, ListNode* l2) {
        ListNode* dummy = new ListNode(-1);
        ListNode* cur = dummy;
        while(l1 && l2)
        {
            if(l1->val < l2->val)
            {
                cur->next = l1;
                l1 = l1->next;
                cur = cur->next;
            }
            else
            {
                cur->next = l2;
                l2 = l2->next;
                cur = cur->next;
            }
        }

        if(l1) cur->next = l1;
        if(l2) cur->next = l2;

        return dummy->next;
    }
};


活动打卡代码 AcWing 84. 求1+2+…+n

ஐ_4
1小时前
class Solution {
public:
    int getSum(int n) {
        int res = 0;
        if(n == 0) return 0;
        return  res += getSum(n - 1) + n;
    }
};


活动打卡代码 AcWing 16. 替换空格

ஐ_4
1小时前
class Solution {
public:
    string replaceSpaces(string &str) {
        string res = "";
        for(int i = 0; str[i] ; i++)
        {
            if(str[i] == ' ')
            {
                res += "%20";
            }
            else{
                res += str[i];
            }
        }

        return res;
    }
};


活动打卡代码 AcWing 21. 斐波那契数列

ஐ_4
1小时前
class Solution {
public:
    int Fibonacci(int n) {
        if(n <= 1) return n;
        return Fibonacci(n - 2) + Fibonacci(n - 1);
    }
};


活动打卡代码 AcWing 823. 排列

ஐ_4
18小时前
#include <iostream>

using namespace std;

int n ;

void dfs(int begin , int nums[] , bool visit[] )
{
    if(begin > n)
    {
        for(int i = 1; i <= n; i++) cout << nums[i] << ' ' ;
        cout << endl;
    }else{
        for(int i = 1; i <= n; i++)
        {
            if(!visit[i])
            {   
                visit[i] = true;
                nums[begin] = i;
                dfs(begin + 1, nums , visit);
                visit[i] = false;
            }
        }
    }
}


int main()
{

    cin >> n;

    int nums[10] = {0};
    bool visit[10] = {0};

    dfs(1,nums,visit);

    return 0;
}



ஐ_4
20小时前
#include <iostream>

using namespace std;

//反过来
// 求(n,m)到原点
int f(int n ,int m){
    if(n < 0 || m < 0) return 0;

    if(n == 0 && m == 0 ) return 1;
    else return f(n, m - 1) + f(n - 1, m); 
}

int main()
{
    int n,m ; 
    cin >> n >> m;

    cout << f(n,m) << endl;

    return 0;
}


活动打卡代码 AcWing 822. 走方格

ஐ_4
21小时前
#include <iostream>

using namespace std;

//反过来
// 求(n,m)到原点
int f(int n ,int m){
    if(n < 0 || m < 0) return 0;

    if(n == 0 && m == 0 ) return 1;
    else return f(n, m - 1) + f(n - 1, m); 
}

int main()
{
    int n,m ; 
    cin >> n >> m;

    cout << f(n,m) << endl;

    return 0;
}