02 2023 档案

摘要:编写一个算法来判断一个数 n 是不是快乐数。 「快乐数」 定义为: 对于一个正整数,每一次将该数替换为它每个位置上的数字的平方和。 然后重复这个过程直到这个数变为 1,也可能是 无限循环 但始终变不到 1。 如果这个过程 结果为 1,那么这个数就是快乐数。 如果 n 是 快乐数 就返回 true ; 阅读全文
posted @ 2023-02-28 18:59 xiazichengxi 阅读(30) 评论(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 阅读(13) 评论(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 阅读(9) 评论(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 阅读(13) 评论(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 阅读(13) 评论(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 阅读(15) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示
主题色彩