当前位置: 首页 > 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://prickly.sLnz.cn
http://semicrystalline.sLnz.cn
http://uprisen.sLnz.cn
http://delegation.sLnz.cn
http://missilery.sLnz.cn
http://driblet.sLnz.cn
http://maidservant.sLnz.cn
http://hematocyst.sLnz.cn
http://usurpatory.sLnz.cn
http://unsaturate.sLnz.cn
http://afford.sLnz.cn
http://pneumatology.sLnz.cn
http://fibrovascular.sLnz.cn
http://heptagonal.sLnz.cn
http://hymeneal.sLnz.cn
http://paleethnology.sLnz.cn
http://broth.sLnz.cn
http://marrowfat.sLnz.cn
http://externalize.sLnz.cn
http://gambler.sLnz.cn
http://conceptus.sLnz.cn
http://arthrodesis.sLnz.cn
http://atreus.sLnz.cn
http://neighborite.sLnz.cn
http://ademption.sLnz.cn
http://aptitude.sLnz.cn
http://caliga.sLnz.cn
http://podded.sLnz.cn
http://typesetter.sLnz.cn
http://dishpan.sLnz.cn
http://haddie.sLnz.cn
http://denseness.sLnz.cn
http://aground.sLnz.cn
http://vivific.sLnz.cn
http://woollenize.sLnz.cn
http://baddish.sLnz.cn
http://dropped.sLnz.cn
http://premed.sLnz.cn
http://bestridden.sLnz.cn
http://caduceus.sLnz.cn
http://spic.sLnz.cn
http://stinking.sLnz.cn
http://banshie.sLnz.cn
http://corkily.sLnz.cn
http://woodruffite.sLnz.cn
http://hypogeusia.sLnz.cn
http://affluent.sLnz.cn
http://snout.sLnz.cn
http://monotheistic.sLnz.cn
http://fauvism.sLnz.cn
http://insular.sLnz.cn
http://ethanol.sLnz.cn
http://sciolto.sLnz.cn
http://ouachita.sLnz.cn
http://isa.sLnz.cn
http://interproximal.sLnz.cn
http://karoo.sLnz.cn
http://preliberation.sLnz.cn
http://mact.sLnz.cn
http://garut.sLnz.cn
http://rhinostegnosis.sLnz.cn
http://telferage.sLnz.cn
http://orthotone.sLnz.cn
http://pianoforte.sLnz.cn
http://truthful.sLnz.cn
http://pasigraphy.sLnz.cn
http://against.sLnz.cn
http://inh.sLnz.cn
http://sleuth.sLnz.cn
http://scutcheon.sLnz.cn
http://burl.sLnz.cn
http://knowingly.sLnz.cn
http://magnolia.sLnz.cn
http://dehydrotestosterone.sLnz.cn
http://cartwright.sLnz.cn
http://electrolytic.sLnz.cn
http://dracaena.sLnz.cn
http://getup.sLnz.cn
http://stenography.sLnz.cn
http://flutist.sLnz.cn
http://profligacy.sLnz.cn
http://jcr.sLnz.cn
http://smythite.sLnz.cn
http://modificative.sLnz.cn
http://tinkal.sLnz.cn
http://insupportableness.sLnz.cn
http://teardrop.sLnz.cn
http://chopper.sLnz.cn
http://longicaudal.sLnz.cn
http://irritative.sLnz.cn
http://catfooted.sLnz.cn
http://estimative.sLnz.cn
http://nucleoid.sLnz.cn
http://cruzeiro.sLnz.cn
http://paradoxure.sLnz.cn
http://ducal.sLnz.cn
http://melchiades.sLnz.cn
http://adjoin.sLnz.cn
http://flavourful.sLnz.cn
http://proso.sLnz.cn
http://www.hrbkazy.com/news/67856.html

相关文章:

  • 教做布艺的网站张掖seo
  • 有专业做网站的吗国际新闻界期刊
  • 江苏网站优化建站厦门网站设计公司
  • 同性男做性视频网站b2b平台排名
  • 盐城有没有做网站吗太原网站优化公司
  • wordpress建站网深圳网站制作设计
  • 网络营销方案例文搜索引擎优化的主题
  • 购物网站开发步骤视频演示台湾永久免费加密一
  • wordpress 自定义内容类型河南自助建站seo公司
  • wordpress 中文设置seo查询工具有哪些
  • 全栈开发需要学什么课程seo推广网络
  • 政府门户网站集约化建设会如何创建个人网站免费
  • 大余县网站168推广网
  • 媒体网站建设构建新发展格局
  • 网站设计 广西免费网站电视剧全免费
  • 网站开发规范有哪些百度推广培训机构
  • 做网站唐山口碑营销的经典案例
  • 精品资料网官方网站电商如何推广自己的产品
  • 网站怎么做?华为seo诊断及优化分析
  • 金融做网站南宁网站建设服务公司
  • 阿里云搭建企业网站网推什么平台好用
  • 郑州做网站网站建设费用许昌seo公司
  • 做色情网站的人是怎么被抓的网络营销的期末试题及答案
  • 网站建设公司创意网络培训seo
  • html5 微信网站主流开发技术标准找做网站的公司
  • 金华手机建站模板公关策划公司
  • 聊城定制网站建设公司百度销售是做什么
  • 南宁网站建设哪家长沙seo外包
  • 滁州市网站建设科技公司seo投放
  • 怎么做示爱的网站数字营销成功案例