Array, String Methods (1)
Array, String Methods (1)
changed
// checks if arr2 is a sub array of array 1, arr2 = {1, 2}; arr1 = {0, 1, 2,
3, 4}; subArray(arr1, arr2) = true, but if subArray(arr2, arr1) than =
false.
str.substring(0, str.length()/2).equals(str.substring(str.length()/2));
}
if (str.length() % 2 != 0) {
// moves all the elements between start and end including start and
end to the index of newStart and moves the element in newStart to
after the element of end,
1=<newStart<3
Let x = {1, 2, 3, 4, 5, 6}
public static <T> void moveTo(T[] arr, int start, int end, int newStart) {
if (newStart >= start && newStart <= end) return;
int j = arr.length - 1;
//takes the k variables from the end and reverses them and inserts
them to the start.
For example rotateArray(x, 2) for x = {1, 2, 3, 4, 5} results in x = {4,
5, 1, 2, 3}
// finds the max value of array the other one finds the min value
public static int findMax(int[] arr) {
int max = arr[0];
for (int num : arr) {
if (num > max) {
max = num;
}
}
return max;
}
public static int findMin(int[] arr) {
int min = arr[0];
for (int num : arr) {
if (num < min) min = num;
}
return min;
}
1. countOccurrencesA = O(n)
2. sortArray = O(n^2)
3. containsElementA = O(n)
4. OcValA = O(n)
5. insertArray = O(n)
6. subarray = O(n^2)
7. countOccurrencesS = O(n^2)
8. setS = O(n)
9. subString = O(n^2)
10. containsElementS = O(n^2)
11. OcValS = O(n)
12. deleteS = O(n)
13. insertS = O(n)
14. isPrime = O(n)
15. isDouble = O(n)
16. positiveNoneZeroIntegerArray = O(n)
17. copyA = O(n)
18. isPali = O(n)
19. moveTo = O(n)
20. routateArray = O(n)
21. reverseArray = O(n)
22. findMax = O(n)
23. findMin = O(n)
Output:
A random number between min (inclusive) and max (inclusive)