365天挑战LeetCode1000题——Day 067 通过翻转子数组使两个数组相等 环形链表

1460. 通过翻转子数组使两个数组相等

在这里插入图片描述

代码实现(自解)

class Solution {
public:
    bool canBeEqual(vector<int>& target, vector<int>& arr) {
        sort(target.begin(), target.end());
        sort(arr.begin(), arr.end());
        return target == arr;
    }
};

141. 环形链表

在这里插入图片描述

代码实现(自解)

/**
 * DeFinition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    bool hasCycle(ListNode *head) {
        ListNode* slow_ptr = head, *fast_ptr = head;
        while (fast_ptr && fast_ptr->next) {
            slow_ptr = slow_ptr->next;
            fast_ptr = fast_ptr->next->next;
            if (slow_ptr != NULL && slow_ptr == fast_ptr) return true;
        }
        return false;
    }
};

142. 环形链表 II

在这里插入图片描述

代码实现(自解)

/**
 * DeFinition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode *detectCycle(ListNode *head) {
        set<ListNode*> st;
        while (head) {
            if (st.count(head)) return head;
            st.emplace(head);
            head = head->next;
        }
        return NULL;
    }
};

相关文章

显卡天梯图2024最新版,显卡是电脑进行图形处理的重要设备,...
初始化电脑时出现问题怎么办,可以使用win系统的安装介质,连...
todesk远程开机怎么设置,两台电脑要在同一局域网内,然后需...
油猴谷歌插件怎么安装,可以通过谷歌应用商店进行安装,需要...
虚拟内存这个名词想必很多人都听说过,我们在使用电脑的时候...