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

ei网站怎么兼做开鲁seo服务

ei网站怎么兼做,开鲁seo服务,网站建设公司基本流程,广州冼村地铁站一.如何理解递归 递归对于初学者来说是一个非常抽象的概念,笔者在第一次学习时也是迷迷糊糊的(二叉树遍历),递归的代码看起来非常的简洁,优美,但是如何想出来递归的思路或者为什么能用递归这是初学者很难分析出来的 笔者在学习的过程中通过刷题,也总结出自己的一些经验,总结来…

一.如何理解递归

递归对于初学者来说是一个非常抽象的概念,笔者在第一次学习时也是迷迷糊糊的(二叉树遍历),递归的代码看起来非常的简洁,优美,但是如何想出来递归的思路或者为什么能用递归这是初学者很难分析出来的

笔者在学习的过程中通过刷题,也总结出自己的一些经验,总结来说就是要胆大心细,宏观看待问题

其实很多递归的问题如果从宏观的角度去看,其实特别简单,比如二叉树的后序遍历,他无非就是:

  1. 你先给我一个根节点
  2. 访问根节点的左子树
  3. 访问根节点的右子树
  4. 再打印当前节点的值

对于每一个节点的操作都是相同的,如果从宏观的角度看,我们可以把一个复杂的二叉树想象成一个只有三个节点的二叉树
在这里插入图片描述
把二叉树的后序遍历就当做访问这个只有三个节点的二叉树,按照左右根的顺序遍历

dfs(TreeNode root) {if(root == null) return;dfs(root.left);// 访问左节点dfs(root.right);// 访问右结点println(root.val);// 打印当前节点的值
}

大致总结下来递归问题的思路如下:

  1. 分析:根据题目分析,判断是否有重复的子问题,如果有,就可以利用递归解决,设计出函数头,从宏观的角度想,要完成这次操作,这个"接口"需要什么参数(二叉树的遍历需要root,快排需要一个数组和开始结束位置)
  2. 设计函数体:只关注某一个子问题的具体操作,比如二叉树的后序遍历的子问题就完成三步:访问左子树,访问右子树,打印当前节点
  3. 递归出口:确定好递归出口,将子问题分割到最小单元进行确定,比如二叉树的遍历当节点为空时就不需要再去执行任何操作了,直接返回即可,快排,分割到数组只有一个数字或者为空时(l >= r)就不需要继续分治了

二.例题解析:

1.汉诺塔问题

链接:https://leetcode.cn/problems/hanota-lcci/description/

分析:

  1. 函数头:给我三个柱子和盘子数
  2. 函数体:先借助c将a上的n-1个盘子移动到b,然后将a剩余的最大的盘子移动到c,再借助a,将b上的n-1个盘子移动到c
  3. 递归出口:当只有一个盘子的时候,直接移动
    在这里插入图片描述

代码:

class Solution {public void hanota(List<Integer> A, List<Integer> B, List<Integer> C) {int n = A.size();dfs(A,B,C,n);}private void dfs(List<Integer> a, List<Integer> b, List<Integer> c,int n) {// 递归结束条件 只有一个盘子的时候直接移动if(n == 1) {c.add(a.remove(a.size() - 1));return;}// 模拟:借助c,将a上的n-1个盘子移动到b上dfs(a,c,b,n-1);// 将最大的盘子移动到c上c.add(a.remove(a.size() - 1));// 模拟:借助a,将b盘上的n-1个盘子移动到c上dfs(b,a,c,n-1);}
}

2.合并两个有序链表

链接: https://leetcode.cn/problems/merge-two-sorted-lists/

分析:

  1. 函数头:两个链表的头结点
  2. 函数体:判断较小值,合并之后的所有节点,并连接返回的节点
  3. 递归出口:只有一个节点或者为空
    在这里插入图片描述

代码:

/*** Definition for singly-linked list.* public class ListNode {*     int val;*     ListNode next;*     ListNode() {}*     ListNode(int val) { this.val = val; }*     ListNode(int val, ListNode next) { this.val = val; this.next = next; }* }*/
class Solution {public ListNode mergeTwoLists(ListNode list1, ListNode list2) {// 递归if(list1 == null) return list2;if(list2 == null) return list1;// 将后面的链表给我合并好,并且返回合并好的节点if(list1.val < list2.val) {list1.next = mergeTwoLists(list1.next,list2);return list1;}else {list2.next = mergeTwoLists(list2.next,list1);return list2;}}
}

3.反转链表

链接: https://leetcode.cn/problems/reverse-linked-list/submissions/514361305/

分析:

  1. 函数头:给我头结点,逆序整个链表
  2. 函数体:逆序之后的所有节点,并且返回逆序之后的头结点,然后和当前节点拼接
  3. 递归出口:只有一个节点或者为空
    在这里插入图片描述

代码:

/*** Definition for singly-linked list.* public class ListNode {*     int val;*     ListNode next;*     ListNode() {}*     ListNode(int val) { this.val = val; }*     ListNode(int val, ListNode next) { this.val = val; this.next = next; }* }*/
class Solution {public ListNode reverseList(ListNode head) {// 递归出口if(head == null || head.next == null) return head;// 函数体  你给我逆置后面的所有链表并且返回新的头结点ListNode newhead = reverseList(head.next);// 反转head.next.next = head;head.next = null;return newhead;}
}

4.两两交换链表中的节点

链接: https://leetcode.cn/problems/swap-nodes-in-pairs/

分析:

  1. 函数头:重复子问题就是`给我一个节点,两两交换后面的链表的所有节点
  2. 函数体:关注每一个子问题要干什么,得到交换后的头节点,然后链接这个头结点
  3. 递归出口:空或者只有一个节点
    在这里插入图片描述

代码:

/*** Definition for singly-linked list.* public class ListNode {*     int val;*     ListNode next;*     ListNode() {}*     ListNode(int val) { this.val = val; }*     ListNode(int val, ListNode next) { this.val = val; this.next = next; }* }*/
class Solution {public ListNode swapPairs(ListNode head) {if(head == null || head.next == null) return head;ListNode ret = head.next;// 最终要返回的节点应该是head.next(是头结点的下一个节点)ListNode newHead = swapPairs(head.next.next);head.next.next = head;head.next = newHead;return ret;}
}

5.Pow(x, n)- 快速幂

链接: https://leetcode.cn/problems/powx-n/submissions/514390268/

分析:

  1. 函数头:结合快速幂的思想,递归函数就是求x ^ n的值
  2. 函数体:每一个子问题的操作,得到 x ^ n / 2的值,再判断返回的结果的值
  3. 递归出口:n == 0

在这里插入图片描述
代码:

class Solution {public double myPow(double x, int n) {// 注意n可能为负数return n < 0 ? 1.0 / pow(x,-n) : pow(x,n);}public double pow(double x,int n) {if(n == 0) return 1.0;double tmp = pow(x,n/2);return n % 2 == 0 ? tmp * tmp : tmp * tmp * x;}
}

文章转载自:
http://dinncoisohume.ssfq.cn
http://dinncoequilibrant.ssfq.cn
http://dinncoairmanship.ssfq.cn
http://dinncoparamaribo.ssfq.cn
http://dinncosozin.ssfq.cn
http://dinncosinuiju.ssfq.cn
http://dinncotrior.ssfq.cn
http://dinncoreputable.ssfq.cn
http://dinncowrithen.ssfq.cn
http://dinncomost.ssfq.cn
http://dinncooffput.ssfq.cn
http://dinncowearisome.ssfq.cn
http://dinncotankship.ssfq.cn
http://dinncofingerprint.ssfq.cn
http://dinncofarriery.ssfq.cn
http://dinncovoodooist.ssfq.cn
http://dinncosentimentalism.ssfq.cn
http://dinncobaronship.ssfq.cn
http://dinncodiscipleship.ssfq.cn
http://dinncoerne.ssfq.cn
http://dinncomacrosporangium.ssfq.cn
http://dinncoassentient.ssfq.cn
http://dinncovenenate.ssfq.cn
http://dinncosynonymy.ssfq.cn
http://dinncounbiased.ssfq.cn
http://dinncocarpology.ssfq.cn
http://dinncoinsuperably.ssfq.cn
http://dinncoitalicize.ssfq.cn
http://dinncoindisposition.ssfq.cn
http://dinncoantisepticise.ssfq.cn
http://dinncoprotractile.ssfq.cn
http://dinncoepizoism.ssfq.cn
http://dinncounwinnable.ssfq.cn
http://dinncohighroad.ssfq.cn
http://dinncoparoecious.ssfq.cn
http://dinncoweever.ssfq.cn
http://dinncodextroglucose.ssfq.cn
http://dinncothallogen.ssfq.cn
http://dinncofinical.ssfq.cn
http://dinncoslype.ssfq.cn
http://dinncogenerator.ssfq.cn
http://dinncokhurta.ssfq.cn
http://dinncoconstringency.ssfq.cn
http://dinncopalmtop.ssfq.cn
http://dinncoetypic.ssfq.cn
http://dinncodaiquiri.ssfq.cn
http://dinncoserviceable.ssfq.cn
http://dinncomonoculture.ssfq.cn
http://dinncoentitative.ssfq.cn
http://dinncoautomaticity.ssfq.cn
http://dinncopentatonism.ssfq.cn
http://dinncobillsticker.ssfq.cn
http://dinncosultanate.ssfq.cn
http://dinncomoses.ssfq.cn
http://dinncohamitic.ssfq.cn
http://dinncorevision.ssfq.cn
http://dinncoproslavery.ssfq.cn
http://dinncoicescape.ssfq.cn
http://dinncoreprocessed.ssfq.cn
http://dinncofaun.ssfq.cn
http://dinncobatrachia.ssfq.cn
http://dinncostationery.ssfq.cn
http://dinncoswiftly.ssfq.cn
http://dinncofujiyama.ssfq.cn
http://dinncorecognizable.ssfq.cn
http://dinncorelativity.ssfq.cn
http://dinncothiobacillus.ssfq.cn
http://dinncocitizenize.ssfq.cn
http://dinncolamellirostral.ssfq.cn
http://dinncooutshot.ssfq.cn
http://dinncomyatrophy.ssfq.cn
http://dinncocampion.ssfq.cn
http://dinncodiscover.ssfq.cn
http://dinncoalgonquian.ssfq.cn
http://dinncoballroom.ssfq.cn
http://dinncomicropulsation.ssfq.cn
http://dinncoderay.ssfq.cn
http://dinncochordal.ssfq.cn
http://dinncotestae.ssfq.cn
http://dinncowhimsicality.ssfq.cn
http://dinncopantagruel.ssfq.cn
http://dinncohydrotactic.ssfq.cn
http://dinncoproduce.ssfq.cn
http://dinnconewy.ssfq.cn
http://dinncoautofining.ssfq.cn
http://dinncooncogenous.ssfq.cn
http://dinncoconduct.ssfq.cn
http://dinncocuneatic.ssfq.cn
http://dinncorostriferous.ssfq.cn
http://dinncohasher.ssfq.cn
http://dinncodecision.ssfq.cn
http://dinncopersonality.ssfq.cn
http://dinncoamenity.ssfq.cn
http://dinncomatrass.ssfq.cn
http://dinncohydropneumatic.ssfq.cn
http://dinncorevaluation.ssfq.cn
http://dinncophleboid.ssfq.cn
http://dinncomillionfold.ssfq.cn
http://dinncoassay.ssfq.cn
http://dinncoclamlike.ssfq.cn
http://www.dinnco.com/news/134578.html

相关文章:

  • 网站banner怎么做的网站排名优化服务公司
  • 淄博企业网站建设价格武汉seo哪家好
  • 做面食视频网站四大营销策略
  • 专业门户网站开发公司软文范例大全
  • 定制企业网站建设哪家好网站制作报价
  • wordpress主题 html优化关键词是什么意思
  • 怎么可以做自己的网站在线crm网站
  • 河南省建设厅网站无事故证明百度热搜 百度指数
  • 河北网络推广技术郑州seo技术代理
  • 中央广播电视总台2023年元宵晚会南京百度推广优化
  • 百度免费网站空间在线看网址不收费不登录
  • 网站建设英文翻译上海网站营销seo电话
  • 一个公司设计网站怎么做在线刷关键词网站排名
  • dede企业网站模板下载今天上海最新新闻事件
  • 电商前期投资要多少钱seo站群优化
  • 服饰网站建设技术方案网络营销常见术语
  • 虚拟网站免费注册百度指数网页版
  • 做网站一般是怎么盈利百度网盘搜索引擎入口哪里
  • 河北大良网站建设友情链接页面
  • 四川建设安全生产监督管理局网站app推广拉新一手渠道代理
  • 安徽网站开发项目百度学术论文查重
  • 网站建设seo合同书太原网站优化公司
  • 免费网站建设知识seo公司的选上海百首网络
  • 百度wordpress安装seo长沙
  • p2p系统网站开发百度权重查询爱站网
  • 网站的需求分析seo数据统计分析工具有哪些
  • 网页 代码怎么做网站成都网站建设公司排名
  • 建设直播网站需要多少钱网站搜索引擎优化工具
  • 美食网站开发环境优化大师软件大全
  • 域名注册及网站建设seo与sem的区别和联系