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

深圳网站优化效果免费建网站

深圳网站优化效果,免费建网站,三星杭州 两学一做网站,原创小说网站建设源码来记录几个注意事项 1.vector容器里利用find&#xff08;&#xff09;函数 不同于map&#xff08;map有find方法&#xff09;&#xff0c;vector本身是没有find这一方法&#xff0c;其find是依靠algorithm来实现的。 所以要包含头文件 #include <iostream> #include <…

在这里插入图片描述
来记录几个注意事项
1.vector容器里利用find()函数
不同于map(map有find方法),vector本身是没有find这一方法,其find是依靠algorithm来实现的。
所以要包含头文件


#include <iostream>
#include <algorithm>   //find函数的调用需要包含algorithm这一头文件
#include <vector>

另外返回类型并不是int 类型的索引 iterator迭代器类型的

auto inroot=find(vector.begin(),vector.end(),val)//假设在int类型的vector容器里找值为val的位置

2.关于在vector容器里根据找寻到的位置进行切片,前面为新的vector容器,后面为一个新的vector容器
错误写法

vector inleft=inorder(inorder.begin(),inroot);
这里并不是赋值操作,利用赋值是不对的
正确写法

vector<int> inleft(inorder.begin(),inroot);//利用位置inroot 分割出inroot左边的数组 左闭右开
vector<int> inright(inroot+1,inorder.end());//利用位置inroot 分割出inroot右边的数组 左闭右开

解法:递归

class Solution {//前序 中左右//中序 左中右
public:TreeNode* buildTree(vector<int>& preorder, vector<int>& inorder) {if(preorder.empty()||inorder.empty()) return nullptr;//1.根节点肯定是前序的第一个TreeNode* root=new TreeNode(preorder[0]);//2.在中序遍历中找一下根节点的位置 记住这个函数find(begin(),end(),val)auto inroot=find(inorder.begin(),inorder.end(),preorder[0]);//3.根据根节点的位置划分中序遍历中左子树和右子树,位置左边就是左子树,右边就是右子树vector<int> inleft(inorder.begin(),inroot);vector<int> inright(inroot+1,inorder.end());//4.根据中序遍历中左右子树的大小划分前序遍历数组int leftsize=inleft.size();vector<int> preleft(preorder.begin()+1,preorder.begin()+1+leftsize);//不能写成(1,leftsize+1)vector<int> preright(preorder.begin()+1+leftsize,preorder.end());//递归处理左右子树root->left=buildTree(preleft,inleft);root->right=buildTree(preright,inright);return root;}
};

在这里插入图片描述
思路:重新定义排序方式

sort(nums.begin(),nums.end(),[&](int n1,int n2){});
class Solution {
public:string minNumber(vector<int>& nums) {string result;//首先自定义排序方式 int转为字符串//根据排序方式排好的了字符串一一赋值给result字符串就行sort(nums.begin(),nums.end(),[&](int n1,int n2){string s1=to_string(n1),s2=to_string(n2);return s1+s2<s2+s1;//s1+s2<s2+s1,说明s1更小,更小的排前面!});for(auto& num:nums) result+=to_string(num);return result;}
};

在这里插入图片描述

class Solution {
public:int fib(int n) {if(n==0) return 0;if(n==1) return 1;int x=0,y=0,z=1;for(int i=2;i<=n;i++){x=y;y=z;z=(x+y)%1000000007;}return z;}
};
http://www.yidumall.com/news/101638.html

相关文章:

  • 做网站百度新闻源百度知道首页登录入口
  • 子网站怎么做互联网广告怎么做
  • wordpress做公司网站网络优化工程师为什么都说坑人
  • 做网站应该选择怎样的公司东莞seo优化公司
  • 电商购物网站模板百度网盘在线登录
  • 做网站自己买域名永久观看不收费的直播
  • 租车网站建设宝鸡seo排名
  • ps做网站主页图片东莞关键字排名优化
  • 网站管理助手4.0企业宣传方式
  • 小白建站武汉百度推广seo
  • 自媒体网站源码模板dedeseo还有未来吗
  • 网站建设的需求分析网络项目资源网
  • 黑科技wifi蹭网神器seo优化网站教程百度
  • 县城做二手车网站网络科技有限公司
  • 中国平湖首页规划建设局网站zoho crm
  • 网站改版的方式今天最新消息
  • 免费个人网站源码下载代运营电商公司排行榜
  • 网络营销方案策划论文排名优化软件
  • 动态网站开发知识点站长网站工具
  • 美国网页游戏网站2023第二波疫情已经到来
  • 威海网站设计公司黄页引流推广网站软件免费
  • 建设大型网站建设seo关键词怎么选择
  • 可道网站建设网店代运营合同
  • 网站推广软文公司网站seo具体怎么做
  • 网站免费源码下载长沙百度快速排名优化
  • 免费做长图的网站合肥网站优化技术
  • 沈阳网站哪家公司做的好长沙网络营销学校
  • 国外网站建设软件排行榜软文有哪几种类型
  • wordpress调用列表页网站seo入门基础教程
  • 自己做网站卖东西需要交税吗深圳网站开发