We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent c85b585 commit 7a20833Copy full SHA for 7a20833
Data Structures in Java/Level 1/Lecture 5 - Time and Space Complexity/TimeAndSpaceComplexity_DuplicateInArray.java
@@ -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