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

开一个网站需要什么canvas网站在线设计神器

开一个网站需要什么,canvas网站在线设计神器,手机版网站建设费用清单,佛山大型的网站制作文章目录 0.理解递归、搜索与回溯1.面试题 08.06.汉诺塔问题1.1 题目1.2 思路1.3 代码 2. 合并两个有序链表2.1 题目2.2 思路2.3 代码 3.反转链表3.1 题目3.2 思路3.3 代码 4.两两交换链表中的节点4.1 题目4.2 思路4.3 代码 5. Pow(x, n) - 快速幂5.1 题目5.2 思路5.3 代码 0.理…

文章目录

  • 0.理解递归、搜索与回溯
  • 1.面试题 08.06.汉诺塔问题
    • 1.1 题目
    • 1.2 思路
    • 1.3 代码
  • 2. 合并两个有序链表
    • 2.1 题目
    • 2.2 思路
    • 2.3 代码
  • 3.反转链表
    • 3.1 题目
    • 3.2 思路
    • 3.3 代码
  • 4.两两交换链表中的节点
    • 4.1 题目
    • 4.2 思路
    • 4.3 代码
  • 5. Pow(x, n) - 快速幂
    • 5.1 题目
    • 5.2 思路
    • 5.3 代码

0.理解递归、搜索与回溯

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

1.面试题 08.06.汉诺塔问题

1.1 题目

题目链接
在这里插入图片描述

1.2 思路

在这里插入图片描述在这里插入图片描述
在这里插入图片描述

1.3 代码

class Solution {
public:void hanota(vector<int>& a, vector<int>& b, vector<int>& c) {dfs(a, b, c, a.size());}void dfs(vector<int>& a, vector<int>& b, vector<int>& c, int n){if(n == 1){c.push_back(a.back());a.pop_back();return;}dfs(a, c, b, n - 1);c.push_back(a.back());a.pop_back();dfs(b, a, c, n - 1);}
};

2. 合并两个有序链表

2.1 题目

题目链接
在这里插入图片描述
在这里插入图片描述

2.2 思路

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

2.3 代码

class Solution {
public:ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) {if(l1 == nullptr) return l2;if(l2 == nullptr) return l1;if(l1->val < l2->val){l1->next = mergeTwoLists(l1->next, l2);return l1;}else{l2->next = mergeTwoLists(l1, l2->next);return l2;}}
};

3.反转链表

3.1 题目

题目链接
在这里插入图片描述在这里插入图片描述
在这里插入图片描述

3.2 思路

在这里插入图片描述
在这里插入图片描述

3.3 代码

class Solution {
public:ListNode* reverseList(ListNode* head) {if(head == nullptr || head->next == nullptr) return head;ListNode* newHead = reverseList(head->next);head->next->next = head;head->next = nullptr;return newHead;}
};

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

4.1 题目

题目链接
在这里插入图片描述
在这里插入图片描述

4.2 思路

在这里插入图片描述
在这里插入图片描述

4.3 代码

老方法-迭代

class Solution {
public:ListNode* swapPairs(ListNode* head) {if(head == nullptr || head->next == nullptr) return head;ListNode* newhead = new ListNode(0);newhead->next = head;ListNode* prev = newhead, * cur = head, * next = head->next, * nnext = next->next;while(cur && next){// 交换节点prev->next = next;next->next = cur;cur->next = nnext;// 移动prev、cur、next、nnextprev = cur;cur = nnext;if(cur) next = cur->next;if(next) nnext = next->next;}prev = newhead->next;delete newhead;return prev;}
};

新方法-递归

/*** Definition for singly-linked list.* struct ListNode {*     int val;*     ListNode *next;*     ListNode() : val(0), next(nullptr) {}*     ListNode(int x) : val(x), next(nullptr) {}*     ListNode(int x, ListNode *next) : val(x), next(next) {}* };*/
class Solution {
public:ListNode* swapPairs(ListNode* head) {if(head == nullptr || head->next == nullptr) return head;ListNode* tmp = swapPairs(head->next->next);ListNode* newhead = head->next;head->next->next = head;head->next = tmp;return newhead;}
};

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

5.1 题目

题目链接
在这里插入图片描述

5.2 思路

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

5.3 代码

方法一

class Solution {
public:double myPow(double x, int N) {double ret = 1;long long int n = N;// 如果 n 是负数,将其转换为正数(即取绝对值),并将底数 x 变为  1/xif(n < 0){n = -n;x = 1/x;}while(n){// 检查 n 的最低位是否为 1(通过 n & 1 判断)。如果是 1,则将当前的 x 乘到 ret 中。这是因为当前位对应的幂需要被累乘到结果中。if(n & 1)ret *= x;// 将 x 平方(即 x *= x),相当于将指数翻倍。// 将 n 右移一位(即 n >>= 1),相当于去掉当前最低位,处理下一位。x *= x;n >>= 1;}return ret;}
};

方法二 - 递归

class Solution {
public:double myPow(double x, int n) {// -2^31 <= n <= 2^31// 当n是负的很大的数时,会越界,所以需要将N强转成long longreturn n > 0 ? Pow(x, n) : Pow(1/x, - (long long)n);     }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://www.dtcms.com/wzjs/785878.html

相关文章:

  • 什么行业应该做网站wordpress 模板层级
  • 义乌做网站的公司有哪些建e室内设计网 周婷
  • 网站系统升级需要多久成品网站源码是1688吗
  • 请问如何做网站中国乐清网官网
  • 用c 来建设网站江门seo计费管理
  • 视频logo免费生成网站软件中国建设网网站
  • 个人备案的网站可以做商城新媒体营销的方式
  • 宁波免费做网站平稳有序推进网站建设
  • 句容网站wordpress汉化模板
  • 建设通网站上能查到的企业怎么改wordpress字体大小
  • 开一家代做网站的公司我要做自媒体要怎么开始
  • 济南免费网站建设网站群内容管理系统
  • 个人网站做哪种能赚钱wordpress很强大
  • 骏域网站当地公交建设公司的官网
  • 手机wap网站特效建设银行网上营业厅
  • 青浦网站设计制作北京谷歌seo
  • 专业做网站设计哪家好去三亚要下载什么app?
  • 长春seo公司网站嵌入式软件开发项目
  • 淘宝网站怎么做的国外建站数据
  • 抚宁区建设局网站网站收录大幅度下降
  • 网站建设前台和后台设计基于android的移动互联网开发
  • 微信公众号seo长沙网站优化
  • 程序员做游戏还是做网站好wordpress+用户组
  • 天津重型网站建设风格网站没有内容可以备案吗
  • 南京浦口住房与城乡建设局网站互联网+创业项目ppt成品
  • 网站地图咋做做网站用什么服务器好
  • 平阴网站建设费用crm客户管理系统功能
  • 做生意在哪个网站做深圳专业做网站设计
  • 免费建站的网站99个人网站的域名注册
  • 做网站怎么做连接点下一个页面网页设计与制作教程教科书