-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCubes.java
More file actions
46 lines (41 loc) Β· 968 Bytes
/
Copy pathCubes.java
File metadata and controls
46 lines (41 loc) Β· 968 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package day4;
public class Cubes {
/*
time complexity: O(1)
space complexity: O(1)
*/
public static void main(String[] args) {
// printCubes(1, 10);
printCubes(new int[] {1, 2, -10, -5});
}
// n
// n^3
/*
time complexity: O(1)
space complexity: O(1)
*/
private static int cube(int number) {
// pow(a b) O(log(b)) log(3)
return (int) Math.pow(number, 3);
}
/*
time complexity: O(b - a)
space complexity: O(1)
*/
private static void printCubes(int a, int b) {
for (int i = a ; i <= b ; i++) {
System.out.print(cube(i) + " ");
}
}
// {1, -5, 20}
// 1 -125 8000
/*
time complexity: O(n)
space complexity: O(1)
*/
private static void printCubes(int[] array) {
for (int element : array) {
System.out.print(cube(element) + " ");
}
}
}