<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                ## 二叉搜索樹 ### 定義 * 節點的左子樹只包含 小于 當前節點的數。 * 節點的右子樹只包含 大于 當前節點的數。 * 所有左子樹和右子樹自身必須也是二叉搜索樹。 ### 判斷平衡二叉樹 ~~~ /** * 驗證二叉搜索樹 * 節點的左子樹只包含 小于 當前節點的數。 * 節點的右子樹只包含 大于 當前節點的數。 * 所有左子樹和右子樹自身必須也是二叉搜索樹。 * @Author: mango * @Date: 2022/4/11 11:07 下午 */ public class BSTTree { public boolean isValidBST(TreeNode root) { return isBST(root).isBST; } public BSTInfo isBST(TreeNode node){ if(node == null){ return null; } BSTInfo left = isBST(node.left); BSTInfo right = isBST(node.right); int min = node.val; int max = node.val; // 找到左樹和右樹里的最大值和最小值 if(left != null){ min = Math.min(min,left.min); max = Math.max(max,left.max); } if(right != null){ min = Math.min(min,right.min); max = Math.max(max,right.max); } // 默認為true,找到不是bst的情況設置為false boolean isBST = true; // 左樹不空,左樹不是bst或者左樹最大值大于等于節點的值 if(left != null && (!left.isBST || left.max >= node.val)){ isBST = false; } // 右樹不空,右樹不是bst或者右樹最小值小于等于節點的值 if(right != null && (!right.isBST || right.min <= node.val)){ isBST = false; } return new BSTInfo(isBST,min,max); } } // 收集信息 class BSTInfo{ public boolean isBST; public int min; public int max; public BSTInfo(boolean isBST, int min,int max) { this.isBST = isBST; this.min = min; this.max = max; } } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看