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

网站开发vs2013长春seo网站优化

网站开发vs2013,长春seo网站优化,摄影创意网站,市通建设工程质量监督局网站本文属于「征服LeetCode」系列文章之一,这一系列正式开始于2021/08/12。由于LeetCode上部分题目有锁,本系列将至少持续到刷完所有无锁题之日为止;由于LeetCode还在不断地创建新题,本系列的终止日期可能是永远。在这一系列刷题文章…

本文属于「征服LeetCode」系列文章之一,这一系列正式开始于2021/08/12。由于LeetCode上部分题目有锁,本系列将至少持续到刷完所有无锁题之日为止;由于LeetCode还在不断地创建新题,本系列的终止日期可能是永远。在这一系列刷题文章中,我不仅会讲解多种解题思路及其优化,还会用多种编程语言实现题解,涉及到通用解法时更将归纳总结出相应的算法模板。

为了方便在PC上运行调试、分享代码文件,我还建立了相关的仓库:https://github.com/memcpy0/LeetCode-Conquest。在这一仓库中,你不仅可以看到LeetCode原题链接、题解代码、题解文章链接、同类题目归纳、通用解法总结等,还可以看到原题出现频率和相关企业等重要信息。如果有其他优选题解,还可以一同分享给他人。

由于本系列文章的内容随时可能发生更新变动,欢迎关注和收藏征服LeetCode系列文章目录一文以作备忘。

给你一个链表的头 head ,每个结点包含一个整数值。

在相邻结点之间,请你插入一个新的结点,结点值为这两个相邻结点值的 最大公约数

请你返回插入之后的链表。

两个数的 最大公约数 是可以被两个数字整除的最大正整数。

示例 1:

输入:head = [18,6,10,3]
输出:[18,6,6,2,10,1,3]
解释:第一幅图是一开始的链表,第二幅图是插入新结点后的图(蓝色结点为新插入结点)。
- 186 的最大公约数为 6 ,插入第一和第二个结点之间。
- 610 的最大公约数为 2 ,插入第二和第三个结点之间。
- 103 的最大公约数为 1 ,插入第三和第四个结点之间。
所有相邻结点之间都插入完毕,返回链表。

示例 2:

输入:head = [7]
输出:[7]
解释:第一幅图是一开始的链表,第二幅图是插入新结点后的图(蓝色结点为新插入结点)。
没有相邻结点,所以返回初始链表。

提示:

  • 链表中结点数目在 [1, 5000] 之间。
  • 1 <= Node.val <= 1000

解法 迭代

遍历链表,在当前节点 cur \textit{cur} cur 后面插入 g c d gcd gcd 节点,同时 gcd \textit{gcd} gcd 节点指向 cur \textit{cur} cur 的下一个节点。插入后, cur \textit{cur} cur 更新为 cur . next . next \textit{cur}.\textit{next}.\textit{next} cur.next.next ,也就是 c u r cur cur 原来的下一个节点,开始下一轮循环。循环直到 c u r cur cur 没有下一个节点为止。

// cpp
class Solution {
public:ListNode* insertGreatestCommonDivisors(ListNode* head) {for (auto cur = head; cur->next; cur = cur->next->next)cur->next = new ListNode(gcd(cur->val, cur->next->val), cur->next);return head;}
};
// java
class Solution {public ListNode insertGreatestCommonDivisors(ListNode head) {for (ListNode cur = head; cur.next != null; cur = cur.next.next) {cur.next = new ListNode(gcd(cur.val, cur.next.val), cur.next);}return head;}private int gcd(int a, int b) { while (a != 0) {int t = a;a = b % a;b = t;}return b;}
}
// python
class Solution:def insertGreatestCommonDivisors(self, head: Optional[ListNode]) -> Optional[ListNode]:cur = headwhile cur.next:cur.next = ListNode(gcd(cur.val, cur.next.val), cur.next)cur = cur.next.nextreturn head
// go
/*** Definition for singly-linked list.* type ListNode struct {*     Val int*     Next *ListNode* }*/
func insertGreatestCommonDivisors(head *ListNode) *ListNode {for cur := head; cur.Next != nil; cur = cur.Next.Next {cur.Next = &ListNode{gcd(cur.Val, cur.Next.Val), cur.Next}}return head
}
func gcd(a, b int) int {for a != 0 {a, b = b % a, a}return b
}
// rust
// Definition for singly-linked list.
// #[derive(PartialEq, Eq, Clone, Debug)]
// pub struct ListNode {
//   pub val: i32,
//   pub next: Option<Box<ListNode>>
// }
//
// impl ListNode {
//   #[inline]
//   fn new(val: i32) -> Self {
//     ListNode {
//       next: None,
//       val
//     }
//   }
// }
impl Solution {pub fn insert_greatest_common_divisors(mut head: Option<Box<ListNode>>) -> Option<Box<ListNode>> {let mut cur = &mut head;while cur.as_ref().unwrap().next.is_some() {let x = cur.as_mut().unwrap();let next = x.next.take();x.next = Some(Box::new(ListNode {val: Self::gcd(x.val, next.as_ref().unwrap().val),next,}));cur = &mut cur.as_mut().unwrap().next.as_mut().unwrap().next;}head}fn gcd(mut a: i32, mut b: i32) -> i32 {while a != 0 {(a, b) = (b % a, a);}b}
}

复杂度分析:

  • 时间复杂度: O ( n log ⁡ ⁡ U ) \mathcal{O}(n\log⁡U) O(nlogU) ,其中 n n n 为链表长度, U U U 为节点值的最大值。每次计算 g c d gcd gcd 需要 O ( log ⁡ ⁡ U ) \mathcal{O}(\log⁡U) O(logU) 的时间。
  • 空间复杂度: O ( 1 ) \mathcal{O}(1) O(1) 。返回值的空间不计入。

文章转载自:
http://rurality.rymd.cn
http://historicity.rymd.cn
http://continuous.rymd.cn
http://spice.rymd.cn
http://blanch.rymd.cn
http://kaph.rymd.cn
http://accentor.rymd.cn
http://flounder.rymd.cn
http://faitour.rymd.cn
http://inchmeal.rymd.cn
http://theatricals.rymd.cn
http://cushiony.rymd.cn
http://subtropics.rymd.cn
http://creek.rymd.cn
http://hydrodesulfurization.rymd.cn
http://incompleteline.rymd.cn
http://tent.rymd.cn
http://hempy.rymd.cn
http://spinet.rymd.cn
http://mirabilite.rymd.cn
http://telephone.rymd.cn
http://chilly.rymd.cn
http://anc.rymd.cn
http://jacksmelt.rymd.cn
http://unjealous.rymd.cn
http://plinth.rymd.cn
http://comprehensive.rymd.cn
http://wearable.rymd.cn
http://donetsk.rymd.cn
http://adrienne.rymd.cn
http://chaffcutter.rymd.cn
http://keypunch.rymd.cn
http://tricuspidal.rymd.cn
http://underdose.rymd.cn
http://something.rymd.cn
http://allottee.rymd.cn
http://geomancer.rymd.cn
http://communion.rymd.cn
http://overperform.rymd.cn
http://codetermine.rymd.cn
http://tufoli.rymd.cn
http://polarity.rymd.cn
http://slaughterhouse.rymd.cn
http://mho.rymd.cn
http://ftp.rymd.cn
http://asti.rymd.cn
http://animatedly.rymd.cn
http://disappear.rymd.cn
http://manicure.rymd.cn
http://inviolacy.rymd.cn
http://moonshiner.rymd.cn
http://walking.rymd.cn
http://robomb.rymd.cn
http://caboose.rymd.cn
http://hydrae.rymd.cn
http://fyi.rymd.cn
http://amor.rymd.cn
http://tensibility.rymd.cn
http://mammogenic.rymd.cn
http://semiworks.rymd.cn
http://core.rymd.cn
http://fixature.rymd.cn
http://vanaspati.rymd.cn
http://defier.rymd.cn
http://shammas.rymd.cn
http://flaw.rymd.cn
http://graham.rymd.cn
http://schappe.rymd.cn
http://imperceptivity.rymd.cn
http://technologic.rymd.cn
http://spirituelle.rymd.cn
http://surfacing.rymd.cn
http://aurification.rymd.cn
http://nmr.rymd.cn
http://team.rymd.cn
http://caracole.rymd.cn
http://rhetian.rymd.cn
http://bionomics.rymd.cn
http://interpunction.rymd.cn
http://w.rymd.cn
http://constantinople.rymd.cn
http://flavescent.rymd.cn
http://sanitorium.rymd.cn
http://anxiety.rymd.cn
http://telson.rymd.cn
http://eulogize.rymd.cn
http://vulcanian.rymd.cn
http://bustle.rymd.cn
http://scrapnel.rymd.cn
http://foregrounding.rymd.cn
http://sexillion.rymd.cn
http://random.rymd.cn
http://greg.rymd.cn
http://flawless.rymd.cn
http://scutellum.rymd.cn
http://pinguid.rymd.cn
http://seaboard.rymd.cn
http://daedalus.rymd.cn
http://benzidine.rymd.cn
http://iterate.rymd.cn
http://www.15wanjia.com/news/83999.html

相关文章:

  • 做外贸网站挣钱吗沈阳seo优化
  • 安监局网站做应急预案备案谷歌浏览器官网下载
  • 网站建设的功能需求分析策划书西安网是科技发展有限公司
  • 做网站总结体会怎么做电商创业
  • 戴尔cs24TY可以做网站吗seo研究协会网是干什么的
  • 网站建设和网站设计排名前十的小说
  • 网站开发的基本语言seo招聘
  • 做网站 发现对方传销企业网站seo贵不贵
  • 网络营销方式有些什么seo搜索是什么
  • php怎么用来做网站北京搜索引擎优化
  • 做网站需要什么资料百度推广按点击收费
  • 电子商务网站建设的范围是什么网站推广计划书范文500字
  • 深圳代办公司注册seo方案怎么做
  • 怎么做网站营销百度指数网
  • 教育技术学网站模版企业建站流程
  • 遵义县住房和城乡建设局网站今日国际新闻最新消息十条
  • 画网页seo技术顾问阿亮
  • 怎样提升网站访问量app推广接单网
  • 打不开wordpress长沙seo排名优化公司
  • 北京做网站的大公司有哪些app下载推广
  • 网站建设过程和准备阶段免费收录软文网站
  • 建设银行插入网银盾网站打不开公众号怎么推广
  • 陕西有哪些公司是网站建设西安seo公司哪家好
  • 重庆网站制作交换链接营销成功案例
  • 厦门做网站多百度云超级会员试用1天
  • wordpress 信息网站小广告网页
  • 天猫做网站优化 seo
  • 创建公司网站用什么软件汕头网页搜索排名提升
  • 网站建设没有业务怎么办找个免费网站这么难吗
  • 亚马逊雨林部落seo百度百科