摘要: 给你四个整数数组 nums1、nums2、nums3 和 nums4 ,数组长度都是 n ,请你计算有多少个元组 (i, j, k, l) 能满足: 0 <= i, j, k, l < n nums1[i] + nums2[j] + nums3[k] + nums4[l] == 0 1 class 阅读全文
posted @ 2023-03-02 21:15 xiazichengxi 阅读(23) 评论(0) 推荐(0)
摘要: 给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出 和为目标值 target 的那 两个 整数,并返回它们的数组下标。 你可以假设每种输入只会对应一个答案。但是,数组中同一个元素在答案里不能重复出现。 你可以按任意顺序返回答案。 1 class Solution { 2 阅读全文
posted @ 2023-03-02 19:37 xiazichengxi 阅读(21) 评论(0) 推荐(0)
摘要: 编写一个算法来判断一个数 n 是不是快乐数。 「快乐数」 定义为: 对于一个正整数,每一次将该数替换为它每个位置上的数字的平方和。 然后重复这个过程直到这个数变为 1,也可能是 无限循环 但始终变不到 1。 如果这个过程 结果为 1,那么这个数就是快乐数。 如果 n 是 快乐数 就返回 true ; 阅读全文
posted @ 2023-02-28 18:59 xiazichengxi 阅读(31) 评论(0) 推荐(0)
摘要: 1 class Solution { 2 public: 3 vector<int> intersection(vector<int>& nums1, vector<int>& nums2) { 4 set<int> num1; 5 set<int> num2; 6 vector<int> arr; 阅读全文
posted @ 2023-02-26 18:24 xiazichengxi 阅读(17) 评论(0) 推荐(0)
摘要: 1 class Solution { 2 public: 3 bool isAnagram(string s, string t) { 4 if (s.size() != t.size()) return false; 5 string::iterator s_iter = s.begin(); 6 阅读全文
posted @ 2023-02-26 15:48 xiazichengxi 阅读(12) 评论(0) 推荐(0)
摘要: 1 用容器set 2 用哈希表 3 用双指针法 1 class Solution { 2 public: 3 ListNode* detectCycle(ListNode* head) { 4 set<ListNode*> exclude; 5 ListNode* p,*res; 6 p = hea 阅读全文
posted @ 2023-02-23 10:55 xiazichengxi 阅读(15) 评论(0) 推荐(0)
摘要: 1 //暴力法 2 ListNode* getIntersectionNode(ListNode* headA, ListNode* headB) { 3 if (headA == nullptr || headB == nullptr) return nullptr; 4 ListNode* p, 阅读全文
posted @ 2023-02-22 13:15 xiazichengxi 阅读(17) 评论(0) 推荐(0)
摘要: 给你一个链表,删除链表的倒数第 n 个结点,并且返回链表的头结点。 /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), nex 阅读全文
posted @ 2023-02-21 12:37 xiazichengxi 阅读(16) 评论(0) 推荐(0)
摘要: 给定一个链表,两两交换其中相邻的节点,并返回交换后的链表。 你不能只是单纯的改变节点内部的值,而是需要实际的进行节点交换。 1 class Solution { 2 public: 3 ListNode* swapPairs(ListNode* head) { 4 if(head==nullptr| 阅读全文
posted @ 2022-12-14 18:03 xiazichengxi 阅读(22) 评论(0) 推荐(0)
摘要: 给你单链表的头节点 head ,请你反转链表,并返回反转后的链表。 1 struct ListNode{ 2 int val; 3 ListNode* next; 4 ListNode() : val(0), next(nullptr) {} 5 ListNode(int x) : val(x), 阅读全文
posted @ 2022-12-14 17:31 xiazichengxi 阅读(19) 评论(0) 推荐(0)