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

叫别人做网站需要注意什么问题网络营销的核心是

叫别人做网站需要注意什么问题,网络营销的核心是,网站facebook分享怎么做,wordpress修改上传附件大小链表常用技巧和操作总结 常用技巧 画图 引入虚拟头节点 不要吝啬空间,大胆定义变量 快慢双指针常用操作 创建一个新节点 尾插 头插 两数相加 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.yidumall.com/news/37575.html

相关文章:

  • 网站建设的目的和意义 政府seo培训讲师招聘
  • 价目表app制作陕西seo顾问服务
  • 怎么用asp做网站友情链接查询友情链接检测
  • 技术支持 鼎维重庆网站建设专家能让网络非常流畅的软件
  • 优良的网站邮箱服务器提供商isp深圳建站公司
  • 东莞虎门今日疫情最新情况成都网站搜索排名优化公司
  • 大连app开发公司排名随州seo
  • 网页设计师简介seo优化排名方法
  • 在天津做网站的公司怎样进行seo推广
  • 免费在线做网站今日新闻摘抄十条简短
  • php网站开发前端公司页面设计
  • 提高网站的权重的最佳方法石家庄网站seo
  • seo大神做的网站相城seo网站优化软件
  • 网站首页像素优化公司治理结构
  • 中小型企业建设一个网站大概需要多少钱成功的营销案例及分析
  • 淘宝客 wordpress网站宁波谷歌seo
  • 找做牙工作上哪个网站济南百度竞价代运营
  • 大学生网站开发大赛腾讯效果推广
  • 网站设计个人心得google海外版入口
  • 网页设计怎么建站点优化设计三年级上册答案
  • 招聘网站入职分析表怎么做阿里云域名注册网站
  • 西安建设学院网站首页技能培训机构
  • 做企业手机网站淘宝排名查询工具
  • 一起做英语作业网站免费域名申请网站大全
  • 新公司网站建设费用怎么入账青岛网站seo分析
  • 网站模板源码推广软文范例大全500
  • 南昌网站建设电话合肥网站seo推广
  • 永久免费自助建站百度推广系统营销平台
  • 怎样做网址有自己的模板willfast优化工具下载
  • asp网站做文件共享上传广告推广图片