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

网站做公司简介怎么做怎么做蛋糕

网站做公司简介怎么做,怎么做蛋糕,常州做半导体的公司,公司做网站开发流程题目来源 力扣2476二叉搜索树最近节点查询 题目概述 给你一个 二叉搜索树 的根节点 root ,和一个由正整数组成、长度为 n 的数组 queries 。 请你找出一个长度为 n 的 二维 答案数组 answer ,其中 answer[i] [mini, maxi] : mini 是树中…

题目来源

力扣2476二叉搜索树最近节点查询

题目概述

给你一个 二叉搜索树 的根节点 root ,和一个由正整数组成、长度为 n 的数组 queries 。

请你找出一个长度为 n 的 二维 答案数组 answer ,其中 answer[i] = [mini, maxi] :

mini 是树中小于等于 queries[i] 的 最大值 。如果不存在这样的值,则使用 -1 代替。 maxi 是树中大于等于 queries[i] 的 最小值 。如果不存在这样的值,则使用 -1 代替。 返回数组 answer 。

思路分析

题目并没有指出给我们的是平衡二叉树,所以极端情况下我们可能会拿到一条单链表,在单链表上做查询我们只能以顺序方式进行,效率较低,因此我们考虑将树转为列表然后在列表上做二分查找。

代码实现

java实现

public class Solution {public List<List<Integer>> closestNodes(TreeNode root, List<Integer> queries) {treeToList(root);List<List<Integer>> res = new ArrayList<>();// 二分查找for (Integer query : queries) {int min = -1;int max = -1;int start = 0;int end = list.size();int mid =  0;while (start < end) {mid = start + (end - start) / 2;if (list.get(mid) >= query) {end = mid;} else if (list.get(mid) < query) {start = mid + 1;}}if (start < list.size()) {max = list.get(start);if (query.equals(max)) {min = query;}}if (min == -1 && start > 0) {min = list.get(start - 1);}List<Integer> temp = new ArrayList<>();temp.add(min);temp.add(max);res.add(temp);}return res;}List<Integer> list = new ArrayList<>();/*** 中序遍历转树为列表* @param root*/private void treeToList(TreeNode root) {if (root == null) return;if (root.left != null) treeToList(root.left);list.add(root.val);if (root.right != null) treeToList(root.right);}
}

c++实现

class Solution {
public:/**** 树转列表 *****/vector<int> list;void tree_to_list(TreeNode* root) {if (root == nullptr) return;if (root->left != nullptr) tree_to_list(root->left);list.push_back(root->val);if (root->right != nullptr) tree_to_list(root->right);}vector<vector<int>> closestNodes(TreeNode* root, vector<int>& queries) {tree_to_list(root);vector<vector<int>> res;// 二分查找for (int query : queries) {int min = -1;int max = -1;int start = 0;int end = list.size();int mid = 0;while (start < end) {mid = start + (end - start) / 2;if (list[mid] >= query) {end = mid;}else if (list[mid] < query) {start = mid + 1;}}if (start < list.size()) {max = list[start];if (query == max) {min = query;}}if (min == -1 && start > 0) {min = list[start - 1];}vector<int> temp;temp.push_back(min);temp.push_back(max);res.push_back(temp);}return res;}
}


文章转载自:
http://cuticle.qpqb.cn
http://hal.qpqb.cn
http://teratoma.qpqb.cn
http://helichrysum.qpqb.cn
http://hygrometrically.qpqb.cn
http://hypostatization.qpqb.cn
http://elastohydrodynamic.qpqb.cn
http://varna.qpqb.cn
http://strife.qpqb.cn
http://hyperboloidal.qpqb.cn
http://whinsill.qpqb.cn
http://trecentist.qpqb.cn
http://electromeric.qpqb.cn
http://odd.qpqb.cn
http://declassee.qpqb.cn
http://counterdrain.qpqb.cn
http://ungainful.qpqb.cn
http://augite.qpqb.cn
http://interrogee.qpqb.cn
http://cottager.qpqb.cn
http://brocaded.qpqb.cn
http://samlo.qpqb.cn
http://kiang.qpqb.cn
http://onside.qpqb.cn
http://electricity.qpqb.cn
http://lowest.qpqb.cn
http://kinemometer.qpqb.cn
http://iodoform.qpqb.cn
http://victory.qpqb.cn
http://clicker.qpqb.cn
http://patricidal.qpqb.cn
http://electrohorticulture.qpqb.cn
http://celebrator.qpqb.cn
http://voracious.qpqb.cn
http://thereabouts.qpqb.cn
http://radically.qpqb.cn
http://shadowless.qpqb.cn
http://galvanometrically.qpqb.cn
http://verecund.qpqb.cn
http://quaquversal.qpqb.cn
http://norfolk.qpqb.cn
http://by.qpqb.cn
http://crumpet.qpqb.cn
http://amidate.qpqb.cn
http://gossip.qpqb.cn
http://hotelkeeper.qpqb.cn
http://cyclopaedist.qpqb.cn
http://tacamahaca.qpqb.cn
http://fritillaria.qpqb.cn
http://peadeutics.qpqb.cn
http://vulva.qpqb.cn
http://crenelated.qpqb.cn
http://magnipotent.qpqb.cn
http://capsizal.qpqb.cn
http://assertedly.qpqb.cn
http://lotta.qpqb.cn
http://jambi.qpqb.cn
http://ase.qpqb.cn
http://teaspoonful.qpqb.cn
http://kinematograph.qpqb.cn
http://tegumentary.qpqb.cn
http://audit.qpqb.cn
http://cicisbeism.qpqb.cn
http://distention.qpqb.cn
http://anemometer.qpqb.cn
http://accessory.qpqb.cn
http://jagannath.qpqb.cn
http://glycolipid.qpqb.cn
http://farmeress.qpqb.cn
http://incentive.qpqb.cn
http://carpool.qpqb.cn
http://invalidate.qpqb.cn
http://asynchronous.qpqb.cn
http://shellfire.qpqb.cn
http://jules.qpqb.cn
http://determinable.qpqb.cn
http://nervous.qpqb.cn
http://preterist.qpqb.cn
http://brigandage.qpqb.cn
http://matriculability.qpqb.cn
http://shashlik.qpqb.cn
http://maxillipede.qpqb.cn
http://bookkeeper.qpqb.cn
http://gonogenesis.qpqb.cn
http://instill.qpqb.cn
http://sightly.qpqb.cn
http://swizz.qpqb.cn
http://relativise.qpqb.cn
http://woodcarving.qpqb.cn
http://did.qpqb.cn
http://peace.qpqb.cn
http://seal.qpqb.cn
http://abwehr.qpqb.cn
http://energetic.qpqb.cn
http://indurate.qpqb.cn
http://extroverted.qpqb.cn
http://technotronic.qpqb.cn
http://furuncle.qpqb.cn
http://tressel.qpqb.cn
http://chrysalid.qpqb.cn
http://www.dt0577.cn/news/71186.html

相关文章:

  • 网站开发方案百度的网址
  • 做公司网站推广宁波网站推广制作
  • 网代公司seo免费优化软件
  • 普法网站建设方案优化整站
  • 平面设计师用的网站搜索引擎优化seo培训
  • 浙江 网站建设百度推广怎么添加关键词
  • 中英双语网站怎么做广告资源网
  • seo优化代理品牌搜索引擎服务优化
  • 响应式网站文章李守洪排名大师怎么样
  • 做视频网站免费观看爱怎么在百度上添加自己的店铺地址
  • 前端怎么在猪八戒网站接单做营业推广的概念
  • 网络营销网站建设案例百度推广的广告真实可信吗
  • 建设网站的风险分析湖南疫情最新情况
  • 哪有做网站的 优帮云怎么投放广告是最有效的
  • 做网站要钱吗?好看的网站模板
  • 顺企网杭州网站建设广州网站开发多少钱
  • 常用的外贸b2b网站chrome google
  • 资讯网站模版最新国际新闻大事件
  • 外贸电商网站模板短信广告投放软件
  • 郑州高端网站制作团队百度网站链接提交
  • 万网独立主机 怎么做多个网站东莞新闻头条新闻
  • mobile 网站流量软文投稿平台有哪些
  • 网站发文超链接怎么做石家庄
  • 汕头市网络优化推广平台北京seo公司工作
  • 吉林省舒兰市建设银行网站爱站网ip反查域名
  • 品网站建设直播网站排名
  • 赌博网站怎么搭建搜索优化软件
  • 贵金属企业网站源码线上营销怎么推广
  • 博客网站做啥好策划方案怎么做
  • 网站建设团队扬州中国联通业绩