加载中...

摘要: ##反转链表 public: ListNode* reverseList(ListNode* head) { // 1. 递归终止条件 if (head == nullptr || head->next == nullptr) return head;//最后一个是p //注意上面的顺序不能调换!否 阅读全文
posted @ 2021-11-28 13:20 liang302 阅读(16) 评论(0) 推荐(0) 编辑
摘要: 这个直接能代表数组里面的元素 for (int x: nums); ###作用就是迭代容器中所有的元素,每一个元素的临时名字就是x,等同于下边代码,但需要加*号 for (vector<int>::iterator iter = nums.begin(); iter != nums.end(); i 阅读全文
posted @ 2021-11-28 11:11 liang302 阅读(30) 评论(0) 推荐(0) 编辑
摘要: #首先理解 比如一个链表是这样的:let aaa = [1, 2, 3, 4] 那么 aaa.val 1 aaa.next [2, 3, 4]; aaa.next.val 2 ##将vector里的元素一次遍历放到里,构建链表 //当容器存的是结点的时候 vector<ListNode*>a; Li 阅读全文
posted @ 2021-11-28 10:52 liang302 阅读(63) 评论(0) 推荐(0) 编辑
摘要: ##将vector元素放到set中 class Solution { public: bool containsDuplicate(vector<int>& nums) { unordered_set<int> s(nums.begin(), nums.end()); return s.size() 阅读全文
posted @ 2021-11-28 10:51 liang302 阅读(104) 评论(0) 推荐(0) 编辑