Skip to content

Commit 7a20833

Browse files
committed
lec 5
1 parent c85b585 commit 7a20833

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
public class TimeAndSpaceComplexity_DuplicateInArray {
3+
public static int findDuplicate(int[] arr) {
4+
//Your code goes here
5+
6+
// int ans = 0;
7+
8+
// for(int i = 0; i<arr.length; i++){
9+
// for(int j = i+1; j<arr.length;j++){
10+
// if (arr[i]==arr[j]){
11+
// // count++;
12+
// // if (count>=2){
13+
// ans = arr[j];
14+
// //}
15+
// }
16+
// }
17+
// }
18+
19+
// return ans;
20+
21+
int n = arr.length-2;
22+
int sum = 0;
23+
for(int i : arr){
24+
sum+=i;
25+
}
26+
27+
return (sum - ((n*(n+1))/2));
28+
}
29+
30+
}

0 commit comments

Comments
 (0)