Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Java binary search Tree and Array search method

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "Java binary search tree and array search method". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Topic one

Solution method

/ * Definition for a binary tree node. * public class TreeNode {* int val; * TreeNode left; * TreeNode right; * TreeNode () {} * TreeNode (int val) {this.val = val;} * TreeNode (int val, TreeNode left, TreeNode right) {* this.val = val; * this.left = left; * this.right = right; *} * * / class Solution {int ans Int pre; public int minDiffInBST (TreeNode root) {ans = Integer.MAX_VALUE; pre=-1; method (root); return ans;} public void method (TreeNode root) {if (root==null) return; method (root.left); if (pre==-1) {pre= root.val } else {ans = Math.min (ans,root.val-pre); pre = root.val;} method (root.right);}} topic 2

Solution method

Class Solution {public int dominantIndex (int [] nums) {int f = Integer.MIN_VALUE; int fi = 0; int s = Integer.MIN_VALUE; int si = 0; for (int I = 0; if) {s = f; f = nums [I]; fi = I } else if (Nums [I] > s) {s = nums [I];}} if (nums.length==1) return 0; if (2s)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report