-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathExam2_Video.java
79 lines (65 loc) · 2.46 KB
/
Exam2_Video.java
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import java.util.*;
class Video_Task {
public static long method1(String s) {
long accum = 0;
int mult = 0;
for (int i = s.length() - 1; i > -1; i--) {
char digit = s.charAt(i);
accum += ( (int) digit - 48 ) * ( Math.pow(10, mult) );
mult++;
}
return accum;
}
/*
Fill out the below table on video
Fill out blanks in following questions
Big O refers to the tight bound in this question
|-----------------------------------------------|
| Line | Number of Steps |
| long accum = 0 | |
| int mult = 0 | |
| int i = s.length() - 1 | |
| i > -1 | |
| i-- | |
| char digit = s.charAt(i) | |
| accum += ... | |
| mult++ | |
| return accum | |
|-----------------------------------------------|
Runtime Equation: ____
Total runtime: O(___)
*/
public static int[] method2(int[] arr) {
for (int i = 0; i < arr.length; i++) {
if (i % 3 == 0) {
int amount = 1;
for (int j = 0; j < arr.length / 2; j++) {
amount *= arr[i];
}
arr[i] = amount;
}
}
return arr;
}
/*
Fill out the below table on video
Fill out blanks in following questions
Big O refers to the tight bound in this question
|-----------------------------------------------|
| Line | Number of Steps |
| int i = 0 | |
| i < arr.length | |
| i++ | |
| if (i % 3 == 0) | |
| int amount = 1 | |
| int j = 0 | |
| j < arr.length / 2 | |
| j++ | |
| amount *= arr[i] | |
| arr[i] = amount | |
| return arr | |
|-----------------------------------------------|
Runtime Equation: ____
Total runtime: O(___)
*/
}