Search
Algorithms
Logic
shorther version
import java.util.*; class Node { int value; Node left; Node right; public Node(int value) { this.value = value; } } class BST { public static boolean search(Node root, int key) { while(root != null) { if(root.value == key) { return true; } else root=(root.value > key)?root.left:root.right; } return false; } }
- import java.util.*;
- class Node {
- int value;
- Node left;
- Node right;
- public Node(int value) {
- this.value = value;
- }
- }
- class BST {
- public static boolean search(Node root, int key) {
if(root == null) {return false;}- while(root != null) {
- if(root.value == key) {
- return true;
- }
- else
- root=(root.value > key)?root.left:root.right;
if(root.value > key) {root = root.left;} else if(root.value < key) {root = root.right;}- }
- return false;
- }
- }
import java.util.*; public class Average { public static int averageFinder(int[] arr) { return (int)Arrays.stream(arr).average().getAsDouble(); }; }
- import java.util.*;
- public class Average {
- public static int averageFinder(int[] arr) {
return Arrays.stream(arr).sum() / arr.length;- return (int)Arrays.stream(arr).average().getAsDouble();
- };
- }