897. 遞增順序查找樹-未解決

897. 遞增順序查找樹

https://leetcode-cn.com/contest/weekly-contest-100/problems/increasing-order-search-tree/

package com.test;import java.util.ArrayList;
import java.util.Collections;
import java.util.List;/*** @author stono* @date 2018/9/2* 897. 遞增順序查找樹* https://leetcode-cn.com/contest/weekly-contest-100/problems/increasing-order-search-tree/*/
public class Lesson897 {public static void main(String[] args) {TreeNode t1 = new TreeNode(5);TreeNode t2 = new TreeNode(3);TreeNode t3 = new TreeNode(6);TreeNode t4 = new TreeNode(2);TreeNode t5 = new TreeNode(4);TreeNode t6 = new TreeNode(8);TreeNode t7 = new TreeNode(1);TreeNode t8 = new TreeNode(7);TreeNode t9 = new TreeNode(9);t1.left = t2;t1.right = t3;t2.left = t4;t2.right = t5;t3.right = t6;t4.left = t7;t6.left = t8;t6.right = t9;TreeNode.printNode(t1);TreeNode treeNode = increasingBST(t1);System.out.println();TreeNode.printNode(treeNode);}public static TreeNode increasingBST(TreeNode root) {TreeNode left = root;while (true) {if (left.left != null) {left = left.left;}else {break;}}List<Integer> list = new ArrayList<>(8);addAllValue(root, list);// 排序
        Collections.sort(list);TreeNode temp = left;for (int i = 0; i < list.size(); i++) {if (list.get(i) - left.val == 0) {continue;}TreeNode t2 = new TreeNode(list.get(i));temp.right = t2;temp = t2;}return left;}private static void addAllValue(TreeNode root, List<Integer> list) {if (root != null) {list.add(root.val);addAllValue(root.left, list);addAllValue(root.right, list);}}
}

?

轉載于:https://www.cnblogs.com/stono/p/9574315.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/388644.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/388644.shtml
英文地址,請注明出處:http://en.pswp.cn/news/388644.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Azure PowerShell (16) 并行開關機Azure ARM VM

《Windows Azure Platform 系列文章目錄》 并行開機腳本&#xff1a; https://github.com/leizhang1984/AzureChinaPowerShell/blob/master/ARM/2StartAzureARMVM/StartAzureRMVM.txt 并行關機腳本&#xff1a; https://github.com/leizhang1984/AzureChinaPowerShell/blob/mas…

使用Pandas 1.1.0進行穩健的2個DataFrames驗證

Pandas is one of the most used Python library for both data scientist and data engineers. Today, I want to share some Python tips to help us do qualification checks between 2 Dataframes.Pandas是數據科學家和數據工程師最常用的Python庫之一。 今天&#xff0c;我…

Maya開發

Maya開發&#xff08;一&#xff09;-- 緒論 &#xff08;翻譯自Maya官方文檔&#xff09;2008-05-09 15:33 緒論 Autodesk Maya 是一個開放的產品,就是說任何Autodesk以外的人都可以改變Maya現有的特征,或者 增加新的特性.你可以用兩個方法來修改MAYA: ME…

織夢在線報名平臺php,DedeCMSv5

DedeCMS v5國內專業的PHP網站內容管理系統-織夢內容管理系統v5.8 Roadmap狀態 ? 已完成 &#x1f528; 進行中 ? 未完成項目開發可以到織夢開發問題管理中進行交流反饋。&#x1f528; 調整DedeCMS目錄結構&#xff0c;將原有include中外部訪問的內容遷移出去&#xff1b;&am…

pom.xml文件詳解

<project xmlns"http://maven.apache.org/POM/4.0.0" xmlns:xsi"http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd "> <!-- 父項目的坐…

軟件工程第一次作業

&#xff08;1&#xff09;回想一下你初入大學時對計算機專業的暢想 當初你是如何做出選擇計算機專業的決定的&#xff1f; 當初選擇計算機專業是因為之前看大佬們參加信息競賽&#xff0c;覺得很厲害、很有意思&#xff0c;而且也希望能自己做一款游戲出來&#xff0c;所以就選…

置信區間的置信區間_什么是置信區間,為什么人們使用它們?

置信區間的置信區間I’m going to try something a little different today, in which I combine two (completely unrelated) topics I love talking about, and hopefully create something that is interesting and educational.今天&#xff0c;我將嘗試一些與眾不同的東西…

事實上著就是MAYA4.5完全手冊插件篇的內容

不過著好象侵權了&#xff0c;因為&#xff21;&#xff2c;&#xff29;&#xff21;&#xff33;聲明不得一任何方式傳播該手冊的部分或全部_炙墨追零 Maya不為插件提供二進制兼容性。每當發布新版本時&#xff0c;舊插件的源代碼要重新編譯。然而&#xff0c;我們的目標是保…

制作alipay-sdk-java包到本地倉庫

項目要用到支付寶的掃碼支付&#xff0c;后臺使用的maven 問了客服 官方目前沒有 maven 的地址只能手動安裝到本地了&#xff0c;如果建了maven 服務器也可以上傳到服務器上 從支付寶官網上下載sdk 制作本地安裝包 alipay-sdk-java.jar 放到D: 盤根目錄下 執行命令&#xff1a…

php中wlog是什么意思,d-log模式是什么意思

D-Log是一種高動態范圍的視頻素材記錄格式&#xff0c;總而言之這個色彩模式為后期調色提供了更大的空間。在相機和攝影機拍攝時&#xff0c;一顆高性能的傳感器通常支持11檔以上的動態范圍&#xff0c;而在8bit的照片或視頻上&#xff0c;以符合人眼感知的Gamma進行機內處理和…

PowerShell入門(三):如何快速地掌握PowerShell?

如何快速地掌握PowerShell呢&#xff1f;總的來說&#xff0c;就是要盡可能多的使用它&#xff0c;就像那句諺語說的&#xff1a;Practice makes perfect。當然這里還有一些原則和方法讓我們可以遵循。 有效利用交互式環境 一般來說&#xff0c;PowerShell有兩個主要的運行環境…

pca 主成分分析_通過主成分分析(PCA)了解您的數據并發現潛在模式

pca 主成分分析Save time, resources and stay healthy with data exploration that goes beyond means, distributions and correlations: Leverage PCA to see through the surface of variables. It saves time and resources, because it uncovers data issues before an h…

宏觀數據提取

http://219.235.129.58/fbk/checkSession.jsp http://219.235.129.58/indicatorYear.do?methodgetDczdsXml&bgqbDm1 大列表 http://219.235.129.58/indicatorYear.do?methodgetDczdsXml&bgqbDm1&FBZD_FJD0300&timeTypeyear 第二層 http://219.235.129.58/…

UML-- plantUML安裝

plantUML安裝 因為基于intellid idea,所以第一步自行安裝.setting->plugins 搜索plantUML安裝完成后&#xff0c;重啟idea 會有如下顯示安裝Graphviz 下載地址 https://graphviz.gitlab.io/_pages/Download/Download_windows.html配置Graphviz環境變量&#xff1a; dot -ver…

php不發送referer,php – 注意:未定義的索引:HTTP_REFERER

注意&#xff1a;未定義的索引&#xff1a;HTTP_REFERER$http_referer $_SERVER [‘HTTP_REFERER’]我使用這個從教程,它看起來不錯代碼也從包含文件中調用它我該怎么改&#xff1f;我添加了print_r($_ SERVER);現在頁面給了我這個Array ([UNIQUE_ID] > UoSxWa56310AAAwUck…

HDU 最大報銷額 (0 1 背包)

最大報銷額 Time Limit : 1000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Submission(s) : 29 Accepted Submission(s) : 11 Problem Description現有一筆經費可以報銷一定額度的發票。允許報銷的發票類型包括買圖書&#xff08;A類&#xff09…

rstudio 關聯r_使用關聯規則提出建議(R編程)

rstudio 關聯r背景 (Background) Retailers typically have a wealth of customer transaction data which consists of the type of items purchased by a customer, their value and the date they were purchased. Unless the retailer has a loyalty rewards system, they …

PHP進程1608占用了9012,swoole (ERRNO 9012): worker exit timeout, forced to terminate

swoole server下使用了swoole_event_add&#xff0c;在關閉服務的時候日志中出現了提示swWorker_reactor_is_empty (ERRNO 9012): worker exit timeout, forced to terminate并且關閉服務時間比正常情況下要慢。解決方法開啟 reload_async > true 配置注冊onWorderExit回調&…

C#高級應用之CodeDomProvider引擎篇 .

using System; using System.Text; using System.CodeDom.Compiler; using System.Reflection; using Microsoft.CSharp; namespace ToolPackages.CodeDomProvider { public class SampleCodeDomProvider { //代碼生成器對象 private static System.CodeDom.Compiler.Code…

linux—命令匯總

pwd # 顯示當前工作目錄cd /tmp # cd切換工作目錄pwdcd ./dir01 # .當前工作目錄cd ../dir02 # ..上層工作目錄cd - # -前一個工作目錄cd ~ …