-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayOperations.java
More file actions
55 lines (49 loc) · 1.25 KB
/
ArrayOperations.java
File metadata and controls
55 lines (49 loc) · 1.25 KB
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
<<<<<<< HEAD
class ArrayOperations {
static boolean isZeroPresents(int[] arr){
for(int i=0;i<arr.length;i++){
if(arr[i]==0) return true;
}
return false;
}
public static int arrayOperations(int n, int[] arr) {
// code here
if(!isZeroPresents(arr)) return -1;
int cnt=0,temp=0;
for(int i=0;i<n ;i++){
if(arr[i]!=0){
temp++;
}else{
if(temp!=0) cnt++;
temp = 0;
}
}
if(temp!=0) cnt++;
return cnt;
}
}
=======
class ArrayOperations {
static boolean isZeroPresents(int[] arr){
for(int i=0;i<arr.length;i++){
if(arr[i]==0) return true;
}
return false;
}
public static int arrayOperations(int n, int[] arr) {
// code here
if(!isZeroPresents(arr)) return -1;
int cnt=0,temp=0;
for(int i=0;i<n ;i++){
if(arr[i]!=0){
temp++;
}else{
if(temp!=0) cnt++;
temp = 0;
}
}
if(temp!=0) cnt++;
return cnt;
}
}
>>>>>>> 622c86d59ac7148ac8e767904db50c6179b2fd40