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

哪个网站有手机运营最好的网站

哪个网站有手机,运营最好的网站,怎么做网络推广挣钱,做网站大流量有序链表转换二叉搜索树 https://leetcode.cn/problems/convert-sorted-list-to-binary-search-tree/description/ 描述 给定一个单链表的头节点 head #xff0c;其中的元素 按升序排序 #xff0c;将其转换为 平衡 二叉搜索树 示例 1 输入: head [-10,-3,0,5,9] 输出:…有序链表转换二叉搜索树 https://leetcode.cn/problems/convert-sorted-list-to-binary-search-tree/description/ 描述 给定一个单链表的头节点 head 其中的元素 按升序排序 将其转换为 平衡 二叉搜索树 示例 1 输入: head [-10,-3,0,5,9] 输出: [0,-3,9,-10,null,5] 解释: 一个可能的答案是[0-3,9-10,null,5]它表示所示的高度平衡的二叉搜索树示例 2 输入: head [] 输出: []提示 head 中的节点数在[0, 2 * 1 0 4 10^4 104] 范围内- 1 0 5 10^5 105 Node.val 1 0 5 10^5 105 Typescript 版算法实现 1 方案1分治 /*** Definition for singly-linked list.* class ListNode {* val: number* next: ListNode | null* constructor(val?: number, next?: ListNode | null) {* this.val (valundefined ? 0 : val)* this.next (nextundefined ? null : next)* }* }*//*** Definition for a binary tree node.* class TreeNode {* val: number* left: TreeNode | null* right: TreeNode | null* constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {* this.val (valundefined ? 0 : val)* this.left (leftundefined ? null : left)* this.right (rightundefined ? null : right)* }* }*/function sortedListToBST(head: ListNode | null): TreeNode | null {return buildTree(head, null); }function getMedian(left: ListNode | null, right: ListNode | null): ListNode | null {let fast left;let slow left;while (fast ! right fast?.next ! right) {fast fast.next?.next || null;slow slow.next || null;}return slow; }function buildTree(left: ListNode | null, right: ListNode | null): TreeNode | null {if (left right) return null;const mid getMedian(left, right);const root new TreeNode(mid!.val);root.left buildTree(left, mid);root.right buildTree(mid?.next || null, right);return root; }2 方案2分治 中序遍历优化 /*** Definition for singly-linked list.* class ListNode {* val: number* next: ListNode | null* constructor(val?: number, next?: ListNode | null) {* this.val (valundefined ? 0 : val)* this.next (nextundefined ? null : next)* }* }*//*** Definition for a binary tree node.* class TreeNode {* val: number* left: TreeNode | null* right: TreeNode | null* constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {* this.val (valundefined ? 0 : val)* this.left (leftundefined ? null : left)* this.right (rightundefined ? null : right)* }* }*/function sortedListToBST(head: ListNode | null): TreeNode | null {function getLength(head: ListNode | null): number {let length 0;while (head) {length;head head.next;}return length;}function buildTree(left: number, right: number): TreeNode | null {if (left right) return null;const mid Math.floor((left right 1) / 2);const root new TreeNode();root.left buildTree(left, mid - 1);// 更新根节点的值并移动head指针到下一个节点if (head ! null) {root.val head.val;head head.next;}root.right buildTree(mid 1, right);return root;}const length getLength(head);return buildTree(0, length - 1); }3 ) 方案3快慢指针 /*** Definition for singly-linked list.* class ListNode {* val: number* next: ListNode | null* constructor(val?: number, next?: ListNode | null) {* this.val (valundefined ? 0 : val)* this.next (nextundefined ? null : next)* }* }*//*** Definition for a binary tree node.* class TreeNode {* val: number* left: TreeNode | null* right: TreeNode | null* constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {* this.val (valundefined ? 0 : val)* this.left (leftundefined ? null : left)* this.right (rightundefined ? null : right)* }* }*/function sortedListToBST(head: ListNode | null): TreeNode | null {const travese (head,tail) {if(headtail) return nulllet fast headlet slow headwhile(fast!tail fast.next!tail){slow slow.nextfast fast.next.next}const root new TreeNode(slow.val)root.left travese(head,slow)root.right travese(slow.next,tail)return root}return travese(head, null) };
http://www.hkea.cn/news/14562823/

相关文章:

  • 建设网站有哪些农村电商网站有哪些
  • 网站建设和管理情况顺义建站设计
  • 怎么找做网站的网站前端设计要做什么
  • 杭州网站建站公司网站开发招标前提
  • 17网站一起做网店登录品牌推广方案思维导图
  • 手机网站怎么做的软件开发培训学校排名又简单又紧
  • 网站建设 2018md短视频传媒免费版怎么下载
  • 外包网站建设是什么意思模板网站建设的公司
  • 做h5商城网站宁夏交通建设质监局官方网站
  • 衡阳做网站优化网站制作的主要技术
  • 企业网站建设一条页面设计工资有多少
  • 确定网站推广目标搜索引擎优化心得体会
  • 静态网站如何共用一个头部和尾部企业网站建设多少钱
  • 网站建设公司薪酬淘宝官网网页版
  • 网站建站工具购买空间安装wordpress
  • asp装修网站源码旅游电子商务网站建设目的
  • 网站建设指导思想广州哪家网站建设公司好
  • 完全免费建站系统软件开发app制作公司
  • 网站建设的实验报告做外贸网站卖什么东西好
  • 上海做网站的公司哪个好网站项目管理系统
  • 阜阳企业做网站wordpress固定链自定义结构
  • 东阳网站建设哪家好郑州整站关键词搜索排名技术
  • 网站购买域名银川网站建设是什么
  • 厦门的网站制作小程序官网
  • 中交通力建设股份有限公司网站ppt模板红色主题
  • 专做婚纱店设计网站永康好口碑关键词优化
  • 网站前后台建设难吗编程培训心得体会
  • 做个门户网站多少钱电子商务平台的自然人经营者
  • 网站建设的技术准备郑州市建筑工程信息网
  • 字体设计教程网站好如何制作课程网站