当前位置: 首页 > news >正文

徐州做网站公司哪家好什么是网络营销

徐州做网站公司哪家好,什么是网络营销,东营定制网站建设服务,保定建设公司网站链表常用技巧和操作总结 常用技巧 画图 引入虚拟头节点 不要吝啬空间,大胆定义变量 快慢双指针常用操作 创建一个新节点 尾插 头插 两数相加 ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {int carry 0;ListNode* newHead new ListNode, *cur newHea…

链表常用技巧和操作总结

  • 常用技巧
    画图
    引入虚拟头节点
    不要吝啬空间,大胆定义变量
    快慢双指针
  • 常用操作
    创建一个新节点
    尾插
    头插
  1. 两数相加
ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {int carry = 0;ListNode* newHead = new ListNode, *cur = newHead;while (l1 != nullptr && l2 != nullptr) {int num = l1->val + l2->val + carry;carry = num / 10;num = num % 10;cur->next = new ListNode(num);cur = cur->next;l1 = l1->next;l2 = l2->next;}while (l1 != nullptr) {int num = l1->val + carry;carry = num / 10;num = num % 10;cur->next = new ListNode(num);cur = cur->next;l1 = l1->next;}while (l2 != nullptr) {int num = l2->val + carry;carry = num / 10;num = num % 10;cur->next = new ListNode(num);cur = cur->next;l2 = l2->next;}if (carry != 0) {cur->next = new ListNode(carry);}return newHead->next;
}
  1. 两两交换链表中的节点
ListNode* swapPairs(ListNode* head) {if (head == nullptr || head->next == nullptr) return head;ListNode *front = head, *back = front->next, *newHead = new ListNode, *cur = newHead;while (true) {cur->next = back;ListNode* tmp = back->next;back->next = front;front->next = tmp;cur = front;if (tmp != nullptr && tmp->next != nullptr) {front = tmp;back = front->next;} else if (tmp != nullptr && tmp->next == nullptr) {cur->next = tmp;return newHead->next;} else {return newHead->next;}}
}
  1. 重排链表
ListNode* reverse(ListNode* head) {if (head == nullptr || head->next == nullptr) return head;ListNode* newHead = reverse(head->next);head->next->next = head;head->next = nullptr;return newHead;
}
void reorderList(ListNode* head) {ListNode *slow = head, *fast = head;while (fast != nullptr && fast->next != nullptr) {slow = slow->next;fast = fast->next->next;}ListNode* cur1 = head, *cur2 = reverse(slow);ListNode* newHead = new ListNode, *cur = newHead;while (cur1 != cur2 && cur2 != nullptr) {cur->next = cur1;cur1 = cur1->next;cur = cur->next;cur->next = cur2;cur2 = cur2->next;cur = cur->next;}
}
  1. 合并 K 个升序链表
// 解法一
ListNode* mergeKLists(vector<ListNode*>& lists) {// 小根堆priority_queue<ListNode*, vector<ListNode*>, Comp> pq;for (ListNode* e : lists) {if (e != nullptr) {pq.push(e);}}ListNode *newHead = new ListNode, *cur = newHead;while (!pq.empty()) {cur->next = pq.top();cur = cur->next;pq.pop();if (cur->next != nullptr) {pq.push(cur->next);}}return newHead->next;
}// 解法二
ListNode* merge_sort(vector<ListNode*>& lists, int start, int end) {if (start > end) return nullptr;else if (start == end) return lists[start];int mid = start + (end - start) / 2;ListNode* left = merge_sort(lists, start, mid);ListNode* right = merge_sort(lists, mid + 1, end);if (left == nullptr) return right;else if (right == nullptr) return left;ListNode *newHead = new ListNode, *cur = newHead;while (left != nullptr && right != nullptr) {if (left->val < right->val) {cur->next = left;left = left->next;} else {cur->next = right;right = right->next;}cur = cur->next;}while (left != nullptr) {cur->next = left;left = left->next;cur = cur->next;}while (right != nullptr) {cur->next = right;right = right->next;cur = cur->next;}return newHead->next;
}
ListNode* mergeKLists(vector<ListNode*>& lists) {return merge_sort(lists, 0, lists.size() - 1);
}
  1. K 个一组翻转链表
ListNode* reverseKGroup(ListNode* head, int k) {int total = 0;ListNode* cur = head;while (cur != nullptr) {++total;cur = cur->next;}ListNode* newHead = new ListNode;cur = newHead;while (head != nullptr) {int count = k;ListNode* tail = head;if (total >= k) {while (count-- && head != nullptr) {ListNode* tmp = head->next;head->next = cur->next;cur->next = head;head = tmp;}total -= k;}cur = tail;if (total < k) {cur->next = head;break;}}return newHead->next;
}
http://www.hkea.cn/news/520963/

相关文章:

  • 论坛型网站怎么做百度高级检索入口
  • 做百度移动网站排搜素引擎优化
  • 公司创建一个网站需要多少钱想做百度推广找谁
  • 做文献ppt模板下载网站有哪些常德政府网站
  • 青岛网站建设公司排行外链工具在线
  • 网站怎么做显得简洁美观seo数据是什么意思
  • 阿里巴巴开通诚信通后网站怎么做网络优化网站
  • 东莞手机网站价格便宜个人免费建站软件
  • 电子商务网站建设的步骤一般为百度100%秒收录
  • 做企业网站怎么样免费的推广软件下载
  • 拓普网站建设美国搜索引擎
  • 网站开发者工资冯耀宗seo视频教程
  • 软件开发各阶段工作量比例搜索引擎优化的基础是什么
  • 网站怎么做才能将名声打响云搜索app
  • 南阳做网站优化哪家好一级域名生成二级域名
  • 3322动态域名官网郑州seo联系搜点网络效果好
  • 网络营销渠道的类型河北seo基础教程
  • 做微信网站多少钱seo内部优化包括哪些内容
  • 中国城乡建设网站网络优化公司排名
  • 个人网站做淘宝客教程torrentkitty磁力搜索引擎
  • 广州北京网站建设seo培训讲师招聘
  • 手机上免费自己做网站网络营销案例分享
  • 长沙大型网站建设谷歌账号
  • 大兴德艺网站建设发布悬赏任务的推广平台
  • html5制作网站模板百度产品大全首页
  • 贵阳网站建设贵阳百度推广怎么推广
  • 瓮安建设局网站google play三件套
  • 大型门户网站模板营销神器
  • 学设计的网站都有哪些seo和sem
  • 如何做网站流量买卖营销型网站的特点