package bigo; | |
import java.lang.reflect.Array; | |
import java.util.Arrays; | |
public class Analysis { | |
private static boolean isFirstCharA(char[] chars) { | |
if (chars[0] == 'A') | |
return true; | |
else | |
return false; | |
} | |
private static int findLargestNumber(int[] input) { | |
int largestNumber = 0; | |
for (int current : input) { | |
if (current > largestNumber) { | |
largestNumber = current; | |
} | |
} | |
return largestNumber; | |
} | |
private static boolean checkIfDuplicatesExist(int[] input1, int[] input2) { | |
for (int currentInput1 : input1) { | |
for (int currentInput2 : input2) { | |
if (currentInput1 == currentInput2) { | |
return true; | |
} | |
} | |
} | |
return false; | |
} | |
private static int divideByTwo(int input){ | |
int counter = 0; | |
while(input > 1){ | |
input = input/2; | |
counter++; | |
} | |
return counter; | |
} | |
public static void main(String[] args) { | |
// Poor man's tests | |
// O(1) test | |
char[] charArray = new char[10]; | |
charArray[0] = 'A'; | |
System.out.println(isFirstCharA(charArray)); | |
// O(n) test | |
int[] input = new int[3]; | |
input[0] = 10; | |
input[1] = 12; | |
input[2] = 3; | |
System.out.println(findLargestNumber(input)); | |
// O(n^2) test 1 | |
int[] input1 = new int[3]; | |
input1[0] = 10; | |
input1[1] = 12; | |
input1[2] = 3; | |
int[] input2 = new int[3]; | |
input2[0] = 100; | |
input2[1] = 120; | |
input2[2] = 31; | |
System.out.println(checkIfDuplicatesExist(input1, input2)); | |
// O(n^2) test 2 | |
int[] input3 = new int[3]; | |
input1[0] = 10; | |
input1[1] = 12; | |
input1[2] = 3; | |
int[] input4 = new int[3]; | |
input2[0] = 100; | |
input2[1] = 120; | |
input2[2] = 12; | |
System.out.println(checkIfDuplicatesExist(input3, input4)); | |
System.out.println(divideByTwo(64)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment