mirror of
				https://git.wolves.top/wolves/leetcode.git
				synced 2025-11-04 17:26:32 +08:00 
			
		
		
		
	init
This commit is contained in:
		
							
								
								
									
										14
									
								
								23/08/1281.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								23/08/1281.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,14 @@
 | 
			
		||||
class Q1281 {
 | 
			
		||||
public:
 | 
			
		||||
    int subtractProductAndSum(int n) {
 | 
			
		||||
        int plus = 0;
 | 
			
		||||
        int mult = 1;
 | 
			
		||||
        while (n) {
 | 
			
		||||
            int quo = n % 10;
 | 
			
		||||
            n = n / 10;
 | 
			
		||||
            plus += quo;
 | 
			
		||||
            mult *= quo;
 | 
			
		||||
        }
 | 
			
		||||
        return mult - plus;
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
							
								
								
									
										9
									
								
								23/08/1749.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								23/08/1749.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,9 @@
 | 
			
		||||
#include "vector"
 | 
			
		||||
using namespace std;
 | 
			
		||||
 | 
			
		||||
class Q1749 {
 | 
			
		||||
public:
 | 
			
		||||
    int maxAbsoluteSum(vector<int>& nums) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
							
								
								
									
										38
									
								
								23/08/21.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								23/08/21.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,38 @@
 | 
			
		||||
class Q21
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    struct ListNode
 | 
			
		||||
    {
 | 
			
		||||
        int val;
 | 
			
		||||
        ListNode *next;
 | 
			
		||||
        ListNode() : val(0), next(nullptr) {}
 | 
			
		||||
        ListNode(int x) : val(x), next(nullptr) {}
 | 
			
		||||
        ListNode(int x, ListNode *next) : val(x), next(next) {}
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    ListNode *mergeTwoLists(ListNode *l1, ListNode *l2)
 | 
			
		||||
    {
 | 
			
		||||
        ListNode *preHead = new ListNode(-1);
 | 
			
		||||
 | 
			
		||||
        ListNode *prev = preHead;
 | 
			
		||||
        while (l1 != nullptr && l2 != nullptr)
 | 
			
		||||
        {
 | 
			
		||||
            if (l1->val < l2->val)
 | 
			
		||||
            {
 | 
			
		||||
                prev->next = l1;
 | 
			
		||||
                l1 = l1->next;
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                prev->next = l2;
 | 
			
		||||
                l2 = l2->next;
 | 
			
		||||
            }
 | 
			
		||||
            prev = prev->next;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // 合并后 l1 和 l2 最多只有一个还未被合并完,我们直接将链表末尾指向未合并完的链表即可
 | 
			
		||||
        prev->next = l1 == nullptr ? l2 : l1;
 | 
			
		||||
        std::cout << "123";
 | 
			
		||||
        return preHead->next;
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
							
								
								
									
										28
									
								
								23/08/24.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								23/08/24.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,28 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
#include "lists.h"
 | 
			
		||||
 | 
			
		||||
class Q24 {
 | 
			
		||||
public:
 | 
			
		||||
    ListNode *swapPairs(ListNode *head) {
 | 
			
		||||
        if (!head || !head->next) {
 | 
			
		||||
            return head;
 | 
			
		||||
        }
 | 
			
		||||
        ListNode *p1;
 | 
			
		||||
        ListNode *p2;
 | 
			
		||||
        p1 = head;
 | 
			
		||||
        p2 = head->next;
 | 
			
		||||
 | 
			
		||||
        while (!p2){
 | 
			
		||||
            p1->next = p2->next;
 | 
			
		||||
            p2->next = p1;
 | 
			
		||||
 | 
			
		||||
            if(!p1->next){
 | 
			
		||||
                return head;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            p1 = p1->next;
 | 
			
		||||
            p2 = p1->next;
 | 
			
		||||
        }
 | 
			
		||||
        return head;
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
							
								
								
									
										13
									
								
								23/08/Q1388.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								23/08/Q1388.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,13 @@
 | 
			
		||||
//
 | 
			
		||||
// Created by 李洋 on 2023/8/18.
 | 
			
		||||
//
 | 
			
		||||
#include <vector>
 | 
			
		||||
 | 
			
		||||
using namespace std;
 | 
			
		||||
 | 
			
		||||
class Q1388 {
 | 
			
		||||
public:
 | 
			
		||||
    int maxSizeSlices(vector<int> &slices) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
							
								
								
									
										17
									
								
								23/08/Q1572.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								23/08/Q1572.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,17 @@
 | 
			
		||||
#include <vector>
 | 
			
		||||
 | 
			
		||||
using namespace std;
 | 
			
		||||
 | 
			
		||||
class Q1572 {
 | 
			
		||||
public:
 | 
			
		||||
    int diagonalSum_1(vector<vector<int>> &mat) {
 | 
			
		||||
        int sum = 0;
 | 
			
		||||
        for (int i = 0; i < mat.size(); ++i) {
 | 
			
		||||
            sum += mat[i][i] + mat[i][mat.size() - i - 1];
 | 
			
		||||
        }
 | 
			
		||||
        if ((mat.size() & 1) == 1) {
 | 
			
		||||
            sum -= mat[mat.size() / 2][mat.size() / 2];
 | 
			
		||||
        }
 | 
			
		||||
        return sum;
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
							
								
								
									
										14
									
								
								23/08/Q2235.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								23/08/Q2235.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,14 @@
 | 
			
		||||
//
 | 
			
		||||
// Created by 李洋 on 2023/8/19.
 | 
			
		||||
//
 | 
			
		||||
class Q2235 {
 | 
			
		||||
public:
 | 
			
		||||
    int sum(int num1, int num2) {
 | 
			
		||||
        while (num2) {
 | 
			
		||||
            unsigned int carry = (unsigned int) (num1 & num2) << 1;
 | 
			
		||||
            num1 ^= num2;
 | 
			
		||||
            num2 = carry;
 | 
			
		||||
        }
 | 
			
		||||
        return num1;
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
							
								
								
									
										15
									
								
								23/08/Q23.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								23/08/Q23.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,15 @@
 | 
			
		||||
//
 | 
			
		||||
// Created by 李洋 on 2023/8/12.
 | 
			
		||||
//
 | 
			
		||||
#include "../../dataStruct/LinkedList/lists.h"
 | 
			
		||||
 | 
			
		||||
using namespace std;
 | 
			
		||||
class Q23 {
 | 
			
		||||
public:
 | 
			
		||||
    bool compare(const ListNode *a, const ListNode *b) {
 | 
			
		||||
        return a->val < b->val;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    ListNode* mergeKLists(vector<ListNode*>& lists) {
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
							
								
								
									
										22
									
								
								23/08/Q2682.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								23/08/Q2682.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,22 @@
 | 
			
		||||
//
 | 
			
		||||
// Created by 李洋 on 2023/8/16.
 | 
			
		||||
//
 | 
			
		||||
#include "vector"
 | 
			
		||||
using namespace std;
 | 
			
		||||
class Q2682 {
 | 
			
		||||
public:
 | 
			
		||||
    vector<int> circularGameLosers(int n, int k) {
 | 
			
		||||
        vector<bool> visit(n, false);
 | 
			
		||||
        for (int i = k, j = 0; !visit[j]; i += k) {
 | 
			
		||||
            visit[j] = true;
 | 
			
		||||
            j = (j + i) % n;
 | 
			
		||||
        }
 | 
			
		||||
        vector<int> ans;
 | 
			
		||||
        for (int i = 0; i < n; i++) {
 | 
			
		||||
            if (!visit[i]) {
 | 
			
		||||
                ans.emplace_back(i + 1);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return ans;
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
							
								
								
									
										20
									
								
								23/08/Q617.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								23/08/Q617.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,20 @@
 | 
			
		||||
//
 | 
			
		||||
// Created by 李洋 on 2023/8/14.
 | 
			
		||||
//
 | 
			
		||||
#include "../../dataStruct/Tree/Tree.h"
 | 
			
		||||
 | 
			
		||||
class Q617 {
 | 
			
		||||
public:
 | 
			
		||||
    TreeNode* mergeTrees(TreeNode* root1, TreeNode* root2) {
 | 
			
		||||
        if (root1 == nullptr) {
 | 
			
		||||
            return root2;
 | 
			
		||||
        }
 | 
			
		||||
        if (root2 == nullptr) {
 | 
			
		||||
            return root1;
 | 
			
		||||
        }
 | 
			
		||||
        auto merged = new TreeNode(root1->val + root2->val);
 | 
			
		||||
        merged->left = mergeTrees(root1->left, root2->left);
 | 
			
		||||
        merged->right = mergeTrees(root1->right, root2->right);
 | 
			
		||||
        return merged;
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
							
								
								
									
										28
									
								
								23/08/Q88.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								23/08/Q88.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,28 @@
 | 
			
		||||
//
 | 
			
		||||
// Created by 李洋 on 2023/8/13.
 | 
			
		||||
//
 | 
			
		||||
#include <vector>
 | 
			
		||||
using namespace std;
 | 
			
		||||
class Q88 {
 | 
			
		||||
public:
 | 
			
		||||
    void merge(vector<int>& nums1, int m, vector<int>& nums2, int n) {
 | 
			
		||||
        int p1 = 0, p2 = 0;
 | 
			
		||||
        int sorted[m + n];
 | 
			
		||||
        int cur;
 | 
			
		||||
        while (p1 < m || p2 < n) {
 | 
			
		||||
            if (p1 == m) {
 | 
			
		||||
                cur = nums2[p2++];
 | 
			
		||||
            } else if (p2 == n) {
 | 
			
		||||
                cur = nums1[p1++];
 | 
			
		||||
            } else if (nums1[p1] < nums2[p2]) {
 | 
			
		||||
                cur = nums1[p1++];
 | 
			
		||||
            } else {
 | 
			
		||||
                cur = nums2[p2++];
 | 
			
		||||
            }
 | 
			
		||||
            sorted[p1 + p2 - 1] = cur;
 | 
			
		||||
        }
 | 
			
		||||
        for (int i = 0; i != m + n; ++i) {
 | 
			
		||||
            nums1[i] = sorted[i];
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
		Reference in New Issue
	
	Block a user